`
Ydoing
  • 浏览: 100562 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

jQuery自定义动画

 
阅读更多

语法结构

animate(params, speed, callback);
  • params: 包含样式属性的映射。
  • speed:速度参数,可选。
  • callback:在动画完成执行的函数,可选。

实例

要实现一个功能,点击元素时,每次元素在300ms内向右移动100px。

点击前:
这里写图片描述

点击后:
这里写图片描述

jQuery:

                $this.children('li').click(function(){
                    $(this).animate({left: "+=100px"},300);
                    console.log("ccc");

                }); 

html:

                    <ul class="tabs">
                        <li class="tabs-li">
                            <a href="#" class="tab-li-a">欢迎使用</a>
                        </li>
                    </ul> 

css:

.tabs li {
    position: relative;
    width: 100px;
}
.tabs .tab-li-a {
    display: block;
    margin: 1px;
    float: left;
    text-decoration: none;
    color: white;
    background-color: #0099cc;
    padding: 5px 1em;
    border: 1px solid #a1acb8;
}
<script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>

版权声明:本文为博主原创文章,未经博主允许不得转载。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics