How does reveal.js resize elements?

删除回忆录丶 提交于 2019-12-31 10:44:48

问题


I am trying to understand how reveal.js ( http://lab.hakim.se/reveal-js/#/ ) resizes elements dynamically.

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.

(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.)


回答1:


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. Here is how it's used for reveal.js https://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

Mini Tut: CSS Media Queries & Using Available Space | CSS-Tricks




回答2:


Presentations are configured with a "normal" resolution, meaning the resolution the presentation was originally authored at. This is currently set to 960x700 by default.

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. 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

});



回答3:


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.

It checks for browser CSS features like 2d and 3d transforms

    // 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.




回答4:


Reveal.js also uses the zoom property to control the resizing of complete slide on small widths. It dynamically changes the value of zoom property which you can notice if you keep resizing the window.



来源:https://stackoverflow.com/questions/14481582/how-does-reveal-js-resize-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!