4

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

enter image description here

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.

M.R.
  • 1,053
  • 2
  • 13
  • 30

4 Answers4

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>
Filipe Dias
  • 284
  • 1
  • 10
1

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;
Ajay Malhotra
  • 798
  • 4
  • 16
1

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>
tobiasBora
  • 1,542
  • 14
  • 23
0

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

The trick is to combine 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 combine 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

Sourav
  • 365
  • 2
  • 7
  • 17