简体   繁体   English

Reveal.js 如何调整元素的大小?

[英]How does reveal.js resize elements?

I am trying to understand how reveal.js resizes elements dynamically.我试图了解reveal.js如何动态调整元素的大小。

To see this, adjust the height of the page and see how elements (to a certain degree) shrink as the page shrinks.要看到这一点,请调整页面的高度并查看元素如何(在一定程度上)随着页面缩小而缩小。

However, using chrome inspector, I cannot see how this shrinking is actually happening, either in CSS or Javascript.但是,使用 chrome 检查器,我无法看到这种缩小实际上是如何发生的,无论是在 CSS 还是 Javascript 中。

(My interest comes from wanting to improve it, if possible, but I was surprised how hard it was to figure out how it works at all.) (我的兴趣来自于想要改进它,如果可能的话,但我很惊讶弄清楚它是如何工作的。)

Presentations are configured with a "normal" resolution, meaning the resolution the presentation was originally authored at.演示文稿配置为“正常”分辨率,这意味着最初创作演示文稿时使用的分辨率。 This is currently set to 960x700 by default.目前默认设置为 960x700。

Based on that resolution and the aspect ratio derived from it the framework will apply CSS 2D transforms to fit your content inside of any screen size.基于该分辨率和从中派生的纵横比,该框架将应用 CSS 2D 转换以适合您的内容在任何屏幕尺寸内。 There are configuration values to control all of this including limits on how much the framework will ever scale your content.有一些配置值可以控制所有这些,包括限制框架将扩展您的内容的程度。

Reveal.initialize({

    ...

    // The "normal" size of the presentation, aspect ratio will be preserved
    // when the presentation is scaled to fit different resolutions. Can be
    // specified using percentage units.
    width: 960,
    height: 700,

    // Factor of the display size that should remain empty around the content
    margin: 0.1,

    // Bounds for smallest/largest possible scale to apply to content
    minScale: 0.2,
    maxScale: 1.0

});

Have you heard of media queries?你听说过媒体查询吗? This is a technique deployed through CSS that allows you to affect the styling of elements based on the width and height of the window.这是一种通过 CSS 部署的技术,允许您根据窗口的宽度和高度影响元素的样式。 Here is how it's used for reveal.jshttps://github.com/hakimel/reveal.js/blob/master/css/reveal.css这是它如何用于reveal.jshttps://github.com/hakimel/reveal.js/blob/master/css/reveal.css

@media screen and (max-width: 900px), (max-height: 600px) {
    .reveal .slides {
        font-size: 0.82em;
    }
}

@media screen and (max-width: 700px), (max-height: 400px) {
    .reveal .slides {
        font-size: 0.66em;
    }
}

Read On: MDN CSS Media Queries继续阅读: MDN CSS 媒体查询

Mini Tut: CSS Media Queries & Using Available Space | Mini Tut: CSS 媒体查询和使用可用空间 | CSS-Tricks CSS 技巧

If you look at the source code hosted on github https://github.com/hakimel/reveal.js/blob/master/js/reveal.js you can see exactly what it's doing.如果您查看托管在 github https://github.com/hakimel/reveal.js/blob/master/js/reveal.js上的源代码,您可以确切地看到它在做什么。

It checks for browser CSS features like 2d and 3d transforms它检查浏览器 CSS 功能,如 2d 和 3d 转换

    // Detect support for CSS 3D transforms
supports3DTransforms = 'WebkitPerspective' in document.body.style ||
'MozPerspective' in document.body.style ||
'msPerspective' in document.body.style ||
'OPerspective' in document.body.style ||
'perspective' in document.body.style

It uses basic event listeners它使用基本的事件监听器

    // Force a layout when the whole page, incl fonts, has loaded
window.addEventListener( 'load', layout, false );
...
/**
* Binds all event listeners.
*/
function addEventListeners() {

window.addEventListener( 'hashchange', onWindowHashChange, false );
window.addEventListener( 'resize', onWindowResize, false );
...

The source code actually has decent commenting so you should be able to learn quite a bit.源代码实际上有不错的注释,所以你应该能够学到很多东西。

Reveal.js also uses the zoom property to control the resizing of complete slide on small widths. Reveal.js 还使用zoom属性来控制小宽度上完整幻灯片的大小调整。 It dynamically changes the value of zoom property which you can notice if you keep resizing the window.它会动态更改zoom属性的值,如果您不断调整窗口大小,您会注意到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM