• JavaScript(18):点赞功能的实现


        示例代码:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>点赞功能的实现</title>
        <style>
            .container{
                padding: 50px;
                height: 200px;
            }
            .praise{
                position: absolute;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <span class="praise">赞</span>
        </div>
    
        <script src="jquery-1.12.4.js"></script>
        <script>
            $('.praise').click(function () {
                addPraise(this);
            });
    
            function addPraise(self) {
                var fontsize = 15;
                var left = 15;
                var bottom = 0;
    //            left、bottom都是指标签内容到左边框和下边框之间的像素距离
                var opacity = 1;
                var s = document.createElement('span');
                $(s).text('+1');
                $(s).css('position','relative');
    //            相对定位,相对于原本位置的定位
                $(s).css('color','red');
                $(s).css('fontSize',fontsize+'px');
                $(s).css('left',left+'px');
                $(s).css('bottom',bottom+'px');
                $(s).css('opacity',opacity);
                $('.container').append(s);
    
                var val = setInterval(function () {
                    fontsize += 3;
                    left += 2;
                    bottom += 5;
                    opacity -= 0.1;
                    $(s).css('fontSize',fontsize+'px');
                    $(s).css('left',left+'px');
                    $(s).css('bottom',bottom+'px');
                    $(s).css('opacity',opacity);
                    if (opacity<0){
                        clearInterval(val);
                        $('.praise').siblings().remove();
                    }
                },40)
            }
        </script>
    </body>
    </html>

  • 相关阅读:
    20180209-json&pickle&shelve模块
    20180209-shutil模块
    20180209-sys模块
    20180209-os模块
    20180115-Xcode创建多个工程协同开发
    20180108-递归函数
    20180105-Python中dict的使用方法
    Python-编码这趟浑水
    20171218-编程语言的介绍
    20180119-01-RACSignal的基础
  • 原文地址:https://www.cnblogs.com/wangchongzhangdan/p/9409619.html
Copyright © 2020-2023  润新知