Fork me on GitHub

jquery的小插件(按钮抖动)——衍生QQ窗口抖动

1、抖动的按钮

效果预览:http://runjs.cn/detail/tyx8dbag

<script type="text/javascript">
    //shakenum:抖动的次数,shakeDistance:抖动的距离
    jQuery.fn.Shake = function (shakenum , shakeDistance) {
        this.each(function () {
            var jSelf = $(this);
            jSelf.css({ position: 'relative' });
            for (var x = 1; x <= shakenum; x++) {
                jSelf.animate({ left: (-shakeDistance) },50)
                .animate({ left: shakeDistance }, 50)
                .animate({ left: 0 }, 50);
            }
        });
        return this;
    }
</script>

<script type="text/javascript">
$(function () {
    $('#btn').click(function () {
        $(this).Shake(2, 10, 400);
    });
});
</script>
<input type="button" value="抖动" id="btn" />

 

posted on 2014-10-15 15:14  雨为我停  阅读(395)  评论(0编辑  收藏  举报