javascript - How to fill the screen with image in impress.js? - Stack Overflow

My impress.js slides have images that I would like to fill the screen and center, here's the code:

My impress.js slides have images that I would like to fill the screen and center, here's the code:

<div id="impress">
    <div class="step" data-x="-10000" data-y="100" data-z="0"  data-scale="1">
        Introduction
    </div>
    <div class="step" data-x="-10000" data-y="-1100" data-z="1000" data-scale="1">
        <img src="images/Wallpaper-Abstract-Fractal-Flowers-Lilies.jpg" >
    </div>
</div>

Right now it looks like below, but I'd like the image in the second slide to fill up the screen (maintaining aspect ratio).

Is there some way to zoom in by changing the data-scale or the camera angle? Or will some css tricks suffice? I started with the default example template.

My impress.js slides have images that I would like to fill the screen and center, here's the code:

<div id="impress">
    <div class="step" data-x="-10000" data-y="100" data-z="0"  data-scale="1">
        Introduction
    </div>
    <div class="step" data-x="-10000" data-y="-1100" data-z="1000" data-scale="1">
        <img src="images/Wallpaper-Abstract-Fractal-Flowers-Lilies.jpg" >
    </div>
</div>

Right now it looks like below, but I'd like the image in the second slide to fill up the screen (maintaining aspect ratio).

Is there some way to zoom in by changing the data-scale or the camera angle? Or will some css tricks suffice? I started with the default example template.

Share Improve this question asked Jun 1, 2016 at 6:03 M.R.M.R. 1,0732 gold badges16 silver badges31 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 2

Add this to the css (X is the number of the step in question):

#step-X html,body{
    margin:0;
    height:100%;
    overflow:hidden;
}
#step-X img{
    min-height:100%;
    min-width:100%;
    height:auto;
    width:auto;
    position:absolute;
    top:-100%; bottom:-100%;
    left:-100%; right:-100%;
    margin:auto;
}

and this to the html:

<div class="step" data-rel-x="2000" data-rel-y="0">
<img src="path/to/image.png" alt="">
</div>

You can use this CSS for image, I will work definitely.

/* Set rules to fill background */
min-height: 100%;
min-width: 1024px;
/* Set up proportionate scaling */
width: 100%;
height: auto;
/* Set up positioning */
position: fixed;
top: 0;
left: 0;
bottom:0;
right:0;
margin:auto;

I'm personnaly using the great object-fit: cover/contain; properties, and I set the size of the picture to the size of the viewport, and it's enough. Note that it also works with videos if you want.

.fitImage {
    width:  100vw;
    height: 100vh;
    margin: 0;
    padding:0;
    background: black;
}


.fitImage img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
    <div class="step fitImage" data-x="0" data-y="0" data-scale="2">
        <img src="picture.png" />
    </div>

This answer is pretty late. But it may help some googlers (all of us) later :)

The trick is to bine the attribute data-scale=2 (or a bigger number than 2) on the slide, thus we have <div class="step" data-scale=2></div>

Then we fill this slide with an image and increase the height and width attributes of the image. Finally we have something like this :

<div class="step" data-scale=2> <img src="src/of/image.jpeg" style="position: absolute; left: 0px; top: 0px; z-index: -1; width: 9000px; height: 1000px"> </div>

We can bine data-scale and dimensions (height,width) of the image until we are satisfied with the quality of the image.

Please refer to this link for more details : Hinco (impress.js contributor) Blog

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745630303a4637065.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信