How to implement image zoom

您所在的位置:网站首页 css变大动画 How to implement image zoom

How to implement image zoom

2024-07-16 02:02| 来源: 网络整理| 查看: 265

Method: 1. Use the "@keyframes animation name {}" rule and the "transform:scale (scale);" statement to create a zoom-in animation; 2. Use "picture element {animation: animation name time infinite ;}" statement scaling animation is applied to picture elements.

How to implement image zoom-in animation with css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

In CSS, you can use animation attributes, "@keyframes" rules, and transform: scale() to implement image zoom-in animation.

Example 1:

Copy after login/*css部分*/ @keyframes scaleDraw { /*定义关键帧、scaleDrew是需要绑定到选择器的关键帧名称*/ 0%{ transform: scale(1); /*开始为原始大小*/ } 25%{ transform: scale(1.1); /*放大1.1倍*/ } 50%{ transform: scale(1); } 75%{ transform: scale(1.1); } } .ballon{ width: 150px; height: 200px; background: url("images/balloon.png"); background-size: 150px 200px; -webkit-animation-name: scaleDraw; /*关键帧名称*/ -webkit-animation-timing-function: ease-in-out; /*动画的速度曲线*/ -webkit-animation-iteration-count: infinite; /*动画播放的次数*/ -webkit-animation-duration: 5s; /*动画所花费的时间*/ }Copy after login

The above attributes can also be written together

animation: scaleDraw 5s ease-in-out infinite; -webkit-animation: scaleDraw 5s ease-in-out infinite;Copy after login

Effect:

How to implement image zoom-in animation with css

Example 2:

Copy after login.live{ position: relative; width: 100px; height: 100px; } .live img{ width: 100px; height: 100px; z-index: 0; } @keyframes living { 0%{ transform: scale(1); opacity: 0.5; } 50%{ transform: scale(1.5); opacity: 0; /*圆形放大的同时,透明度逐渐减小为0*/ } 100%{ transform: scale(1); opacity: 0.5; } } .live span{ position: absolute; width: 100px; height: 100px; left: 0; bottom: 0; background: #fff; border-radius: 50%; -webkit-animation: living 3s linear infinite; z-index: -1; } .live span:nth-child(2){ -webkit-animation-delay: 1.5s; /*第二个span动画延迟1.5秒*/ }Copy after login

How to implement image zoom-in animation with css

The essence is to use the delay attribute of animation. The animation-related attributes of the two layers of circles are basically the same. In addition to the outermost circle, the animation-delay attribute is set

(Learning video sharing: css video tutorial)

The above is the detailed content of How to implement image zoom-in animation with css. For more information, please follow other related articles on the PHP Chinese website!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3