Back

jquery animation的一种实现模式 ( an implementation of jquery animation)

发布时间: 2014-06-12 11:17:00

我们在页面中,总是要对某些元素的展示作出动画效果。 

经过实践,我们发现,最好不要在页面的初始化时就设置好某个元素的位置。 而是需要
1. 把它保留原有的元素位置不动。 
2. 使用 jquery.css() 方法设置目标的 初始化位置
3. 使用 jquery.animation() 方法 将目标的位置变回来。 

例如:

  // 正确的办法: 使用JS 先把目标元素设置个偏移量,然后再把它移动回来。
               $('#' + id_selector).children('img').last()
                 .css('margin-left', '+=50px')
                 .animate({ opacity: 1.0, 'margin-left': '-=50' }, 1000, after_call_back )

see: https://github.com/sg552/test_animation/blob/master/animation.js

Back