0

我有一个脚本,它使用 jquery slide 将两个项目(从数据库中随机抽取的文本/视频和背景)移动到右侧,并用从左侧进入的新项目替换它们:

        if (clickType === 0) {
            $("#image_link_1,#image_text_1") .hide("slide", {direction: "right"}, 1250);
            $("#image_link,#image_text") .show("slide", {direction: "left"}, 1250);
            clickType = 1;
        } else if (clickType === 1) {
            $("#image_link,#image_text") .hide("slide", {direction: "right"}, 1250);
            $("#image_link_1,#image_text_1") .show("slide", {direction: "left"}, 1250);
            clickType = 0;
        }
    }).each(function() {
        if (this.complete)
            $(this).load();
    });
}
;

但是,启用了自动播放功能的视频“被推”出页面,即使它们不可见,它们也会开始播放

一旦他们离开屏幕,我该如何杀死他们?

非常感谢

4

3 回答 3

2

remove从回调中调用 a :

$("#image_link_1,#image_text_1") .hide("slide", {direction: "right"}, 1250, function() {
    $(this).remove(); 
});

将此添加到另一个hide

于 2013-06-10T13:29:55.333 回答
1

您可以使用 jQuery.remove()函数来删除/破坏页面上的选定元素。

有关删除功能的更多信息:http: //api.jquery.com/remove/

要定义要删除的元素,请使用:

$(".class").remove();

或者

$("#id").remove();

您也可以始终使用许多其他 jQuery 选择器类型之一。

编辑

您也可以使用回调将其删除。幻灯片完成后,这将删除元素。

$("#image_link,#image_text") .hide("slide", {direction: "right"}, 1250, function(){
    $(this).remove();
});
于 2013-06-10T13:26:04.473 回答
0

用火。

用于$('#selector').remove()从 DOM 中永久删除项目。

于 2013-06-10T13:26:01.373 回答