gpt4 book ai didi

jquery - 使用特定 div 时,.load jquery 函数不起作用

转载 作者:行者123 更新时间:2023-12-01 06:59:26 25 4
gpt4 key购买 nike

这条线不起作用

$('#bookcontainer').load( startSlide );

虽然这一行确实

$(window).load( startSlide );

#bookcontainer 是一个包含四个图像的 div

这是我的整个代码:

// JavaScript Document
$('#bookcontainer').load( startSlide );

var slide;

$('#slider').hover(
function() {
$('.arrow').show();
},
function() {
$('.arrow').hide();
});

function startSlide() {
$('.book').show();
slide = setInterval(slideR, 5000);
}


function slideR() {
$('.book').first().css('left', '960px').appendTo('#bookcontainer').animate(
{
"left": "-=960px"
}, {
duration: 1000,
easing: 'easeOutCubic'
});

}


function slideL() {
$('.book').last().animate(
{ "left":"+=960px" }, {
duration: 1000,
easing: 'easeOutCubic',
complete: function() {
$(this).prependTo('#bookcontainer').css('left', '0px');
}
});

}


function right() {
clearInterval(slide);
slideR();
startSlide();
};


function left() {
clearInterval(slide);
slideL();
startSlide();
};

最佳答案

加载事件只能在与 URL 关联的元素上处理。来自 documentation :

The load event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the window object.

如果您正在等待所有图像加载,您可以将事件处理程序单独应用于这些图像。

另外:在页面上的所有元素(包括图形)完全加载之前,$(window).load(...) 不会被触发,因此不需要将事件绑定(bind)到div 确保子元素已加载。

如果您发出 AJAX 请求并尝试检测内容何时加载到该 div 中,则应将 startSlide 作为 AJAX 请求的成功回调。

关于jquery - 使用特定 div 时,.load jquery 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5253821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com