goo*_*orp 29
你可以这样做:
...click(function() {
$(...).hide().appendTo(...).fadeIn();
}
Run Code Online (Sandbox Code Playgroud)
尝试这样的事情:
$("selector").hide().fadeIn(1000);
Run Code Online (Sandbox Code Playgroud)
其中1000是项目可以淡入的速度.我将hide()放在那里,假设新DOM元素在创建时是可见的,不确定是否需要.最好的办法是在创建新元素时在新元素上放置"display:none",然后使用fadeIn().
你可以使用其他效果,例如slideUp/slideDown,所以你也可以查看它们.
我过去所做的就是在我想要插入新元素的位置插入零大小的占位符 div。
然后,我将该占位符设置为我想要的大小,然后插入我想要在占位符内显示的元素的隐藏版本,并将其淡入视图中。
淡入完成后,我使用以下代码“展开”占位符以将其删除:
// Essentially, this does the opposite of jQuery.wrap. Here is an example:
//
// jQuery('p').wrap('<div></div>');
// jQuery('p').parent().unwrap().remove();
//
// Note that it is up to you to remove the wrapper-element after its
// childNodes have been moved up the DOM
jQuery.fn.unwrap = function () {
return this.each(function(){
jQuery(this.childNodes).insertBefore(this);
});
};
Run Code Online (Sandbox Code Playgroud)
所有 jQuery 动画功能都有“onComplete”处理程序,允许您在动画完成后启动动画的不同部分,因此实现所有这些并不是一件很麻烦的事情。
此外,保留所有元素的 JavaScript 模型非常有用,而不是依赖缓慢的 DOM 遍历和 jQuery .data() 方法。
| 归档时间: |
|
| 查看次数: |
9953 次 |
| 最近记录: |