• JS框架_(JQuery.js)点赞按钮动画


    百度云盘  传送门  密码: 0ihy

    点赞按钮动画效果:

    (点击一次随机生成一颗小爱心,作为点赞动画~) 

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <title>jQuery点赞按钮动画特效代码</title>
    
     <style type="text/css">
        img{ width: 20px; height: 20px; position: absolute; bottom: 100px; left: 50%; margin-left: -10px; }
        .btn{ width: 100px; height: 30px; border:0; background: #EE4000; color: #fff; position: absolute; bottom: 100px; left: 50%; margin-left: -50px; }
    </style>
    
    </head>
    <body>
    <div class="demo"></div>
    <input id="btn1" type="button" class="btn" value="Gary" />
    
    <script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
    $(function () {
               
     
       $("#btn1").click(function(){
            var x = 100;       
            var y = 900;  
            var num = Math.floor(Math.random() * 3 + 1);
            var index=$('.demo').children('img').length;
            var rand = parseInt(Math.random() * (x - y + 1) + y); 
            
            $(".demo").append("<img src=''>");
            $('img:eq(' + index + ')').attr('src','images/'+num+'.png')
            $("img").animate({
                bottom:"800px",
                opacity:"0",
                left: rand,
            },3000)
            
       })
    }) 
    </script>
    
    
    </body>
    </html>
    index.html

    实现过程:

    三张资源图片就能实现的点赞动画效果

        

      设置图片和按钮样式

    <style type="text/css">
        img{ width: 20px; height: 20px; position: absolute; bottom: 100px; left: 50%; margin-left: -10px; }
        .btn{ width: 100px; height: 30px; border:0; background: #EE4000; color: #fff; position: absolute; bottom: 100px; left: 50%; margin-left: -50px; }
    </style>

     随机选中其中一长图片

        var num = Math.floor(Math.random() * 3 + 1);

     让生成图片出现在随机位置值

    var rand = parseInt(Math.random() * (x - y + 1) + y)

     设置图片透明度和生成位置

            $("img").animate({
                bottom:"800px",
                opacity:"0",
                left: rand,
            },3000)

     为按钮添加点击事件

    $(function () {
               
     
       $("#btn1").click(function(){
            var x = 100;       
            var y = 900;  
            var num = Math.floor(Math.random() * 3 + 1);
            var index=$('.demo').children('img').length;
            var rand = parseInt(Math.random() * (x - y + 1) + y); 
            
            $(".demo").append("<img src=''>");
            $('img:eq(' + index + ')').attr('src','images/'+num+'.png')
            $("img").animate({
                bottom:"800px",
                opacity:"0",
                left: rand,
            },3000)
            
       })
    }) 

    js.append() :使用函数在指定元素的结尾插入内容

      $(".demo").append("<img src=''>")点击按钮后生成图片


    js.attr() :函数返回选择元素的属性值

      $('img:eq(' + index + ')').attr('src','images/'+num+'.png')随机选中一章心形特效产生

     
     jQuery animate() :animate() 方法执行 CSS 属性集的自定义动画
      opacity:设置一个元素的透明度级别
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    (如需转载学习,请标明出处)
  • 相关阅读:
    C语言之基本算法24—黄金切割法求方程近似根
    windows下PHP不能开启pgsql扩展的解决方法
    Linux 文件基本属性
    Android倒计时功能的实现
    hdu2444The Accomodation of Students (最大匹配+推断是否为二分图)
    Asp.net core使用IIS在windows上进行托管
    [Asp.net]web.config customErrors 如何设置?
    [Asp.net mvc]Html.ValidationSummary(bool)
    [C#基础]说说lock到底锁谁?(补充与修改)
    [web.config]如何灵活使用配置文件
  • 原文地址:https://www.cnblogs.com/1138720556Gary/p/9383970.html
Copyright © 2020-2023  润新知