欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

jQuery, how can i do to toggle a margin

shiping1 的头像

Quick and dirty, this would work, although I doubt this is best practice.

var positiveMargin = false;
$('.LoginButton').click(function () {

    if (!positiveMargin) {
        var marginTop = "33px";
        positiveMargin = true;
    }
    else {
        var marginTop = "-160px";
        positiveMargin = false;
    }
     $('.MyBox').animate({
               marginTop: marginTop
               }, {
               duration: 2000,
               specialEasing: {
               marginTop: 'easeOutBounce'
               },
               complete: function () {
               }
             });
 });



来自 http://stackoverflow.com/questions/8173688/jquery-how-can-i-do-to-toggle-a-margin
普通分类: