【问题标题】:jQuery Animate Inline StylejQuery Animate 内联样式
【发布时间】:2013-09-24 05:34:38
【问题描述】:

我正在使用 jQuery 通过将必要的 'margin-top' 作为内联样式添加到 div 来垂直居中 div。

我想通过点击函数删除这个内联样式,并将 div 动画设置为“margin-top: 0”。

到目前为止,我成功清除内联样式的唯一方法是使用..

jQuery('selector').each(function(idx,el){
    el.style.marginTop='';
});

但这会使 div 跳到顶部而不是对其进行动画处理。任何帮助将不胜感激

【问题讨论】:

    标签: jquery css styles inline margin


    【解决方案1】:

    试试这个:

    $('selector').each(function(idx,el){
    
          $(el).animate({
                marginTop : 0
            },1000);
    
    });
    

    【讨论】:

      【解决方案2】:

      使用.animate() 函数

      jQuery('selector').animate({
          'margin-top' : 0
      });
      

      【讨论】:

      • 谢谢!我以为我早些时候尝试过,但显然我输入了错误。
      猜你喜欢
      • 1970-01-01
      • 2013-05-18
      • 2016-11-19
      • 2012-05-23
      • 2011-03-22
      • 1970-01-01
      • 2013-07-30
      • 2019-04-11
      • 1970-01-01
      相关资源
      最近更新 更多