简体   繁体   English

Css - 动画背景图像 - 缩放效果与循环

[英]Css - animating background image - zoom effect with loop

I'm looking for clean way to archive effect using css3 animations : 我正在寻找使用css3动画存档效果的简洁方法:

I have div, which has css style: 我有div,它有css风格:

background-image:url('image.png');
background-size:cover;
/* Just to note this page has 100% width and 100% height */
width:100%;
height:100;

This two rules, makes image full screen. 这两条规则,使图像全屏。 Now, im looking for a way, to create effect of zoom, for let's say 5 seconds. 现在,我正在寻找一种方法,创造缩放的效果,让我们说5秒钟。 So user on page load see full page background, which is getting smaller, but all the time is 100 % width and height. 因此,用户在页面加载时会看到整页背景,它越来越小,但所有时间都是100%的宽度和高度。

I found some examples, but most of them use :hover effect, and i want to have animation on page load. 我找到了一些例子,但大多数都使用:悬停效果,我希望在页面加载时有动画。

Thanks for advice. 谢谢你的建议。

Start the image background-size as greater than 100% and then use a keyframe animation it 'scale' it down to 100% as the end value. 将图像背景大小设置为大于100%,然后使用关键帧动画将其“缩放”为100%作为结束值。

For a loop, use animation-direction: alternate; 对于循环,使用animation-direction: alternate;

 body { height: 100vh; background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3999/Tilt-Shift_-_Cityscene.jpg); background-size: 110% 110%; background-position: center center; animation: shrink 5s infinite alternate; } @keyframes shrink { 0% { background-size: 110% 110%; } 100% { background-size: 100% 100%; } } 

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

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