Home >Web Front-end >CSS Tutorial >How to implement image zoom-in animation with css

How to implement image zoom-in animation with css

青灯夜游
青灯夜游Original
2022-01-20 15:37:2420514browse

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:

<div class="ballon"></div>
/*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; /*动画所花费的时间*/
        }

The above attributes can also be written together

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

Effect:

How to implement image zoom-in animation with css

Example 2:

 <div class="live">
         <img src="images/live.png" alt="">
         <span></span>
         <span></span>
 </div>
.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秒*/
        }

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn