码迷,mamicode.com
首页 > 其他好文 > 详细

仿今日头条按钮loading效果

时间:2018-01-21 11:04:37      阅读:826      评论:0      收藏:0      [点我收藏+]

标签:inline   char   addclass   gpo   width   load   代码   min   for   

效果

技术分享图片

技术分享图片

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>btn</title>
    <style>
        .btnc{
            width: 100px;
            height: 30px;
            line-height: 30px;
            font-size:14px;
            text-align: center;
            border: 1px solid transparent;
            border-radius: 4px;
            background-color: #d9534f;
            border-color: #d43f3a;
            position: relative;
        }
        .btnc .btn-progress{
            display: none;
        }
        .btnc .btnl{
            display: block;
        }
        .btnc.progress .btn-progress{
            display: inline-block !important;
        }
        .btnc.progress .btnl{
            display: none !important;
        }
        .btnl{
            text-decoration: none;
        }
        .btnl:link,.btnl:visited,.btnl:hover,.btnl:active{
            color:#fff;
        }
        .btnl:hover,.btnl:active{
            background-color: #c0534f;
        }
        .btn-progress{
            display: inline-block;
            width:16px;
            height: 16px;
            border:1px solid #fff;
            border-top:0;            
            border-radius: 50%;
            -webkit-border-radius:50%;
            animation: progress .6s linear infinite;
            position: absolute;
            margin:auto;
            top:0;
            left:0;
            right:0;
            bottom:0;
        }
        @keyframes progress{
            0%{
                transform:rotate(0);
                -webkit-transform:rotate(0);
            }
            100%{
                transform:rotate(360deg);
                -webkit-transform:rotate(360deg);
            }
        }
        @-webkit-keyframes progress{
            0%{
                transform:rotate(0);
                -webkit-transform:rotate(0);
            }
            100%{
                transform:rotate(360deg);
                -webkit-transform:rotate(360deg);
            }
        }
    </style>
</head>
<body>
    <div class="j-btnc btnc">
        <a href="javascript:;" class="btnl">提交</a>
        <span class="btn-progress"></span>
    </div>
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script>
        $(.j-btnc).click(function(){
            var $btn = $(this);
            $btn.addClass(progress);

            var p = $.Deferred();
            p.then(function(){
                $btn.removeClass(progress);
            }).catch(function(){
                $btn.removeClass(progress);
            });

            setTimeout(function(){
                p.resolve();
            },200000);
        });
    </script>
</body>
</html>

 

仿今日头条按钮loading效果

标签:inline   char   addclass   gpo   width   load   代码   min   for   

原文地址:https://www.cnblogs.com/mengff/p/8322673.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!