隐藏某个DIV时触发功能的最佳方法是什么。
我想在隐藏元素时从页面中销毁一些Flash对象,并在显示元素时重新创建它们。
e.g。
<div id="flashContainer> // flash object </div>
$("#flashContainer).hide(); //trigger function that destroys the flash object
$("#flashContainer).show(); //trigger function that creates the flash object
背景:
我想要这样做的原因是,我有一个很长的页面,有一些导航“逐步完成”div,好像它们是页面一样。在IE中,所有这些隐藏的div加载闪存并开始下载视频,在此过程中占用内存和带宽
答案 0 :(得分:1)
$("#flashContainer:hidden").show();
取自jQuery官方网页,这有帮助吗?
你能更具体一点吗?
答案 1 :(得分:1)
show()和hide()方法的jQuery provides an override,允许您传递动画完成后触发的回调函数
.show(持续时间,[回调])
你可以像
一样使用它$('#flashContainer').hide('slow', function(e) {
//put your code here to remove your flash
$('#flashId').remove(); //something like this maybe
alert('hidden');
});
$('#flashContainer').show('slow', function(e) {
//add your flash here
});
但是在show()
的情况下,flashcontainer
将在加载Flash对象之前显示,因此您可能需要在调用show()
之前创建闪存
$('#flashcontainer').append('<object><!-- your flash html here --></object>');
$('#flashcontainer').show();
答案 2 :(得分:0)
最好显示和隐藏flash对象,而不是装箱和破坏。
像
这样的东西$("#flashContainer).hide("slow", function(){
$("#yourflashobjid").hide();
});
$("#flashContainer).show("slow", function(){
$("#yourflashobjid").show();
});