Javascript Jquery定时器滑动函数
现在我有一个div,它从右向左滑动,然后从右向左滑动回到原来的位置。但总的来说,这并不是我想要的工作方式。我的主要目标是:让用户将鼠标悬停在主div上,然后拉出滑动div。需要技巧的部分如下:如果用户忘记将俯冲向后滑动,我想给它一个时间框架,使其在经过一定时间后自动关闭。以下是我目前的工作代码: 我的javascript函数:Javascript Jquery定时器滑动函数,javascript,jquery,jquery-ui,javascript-events,Javascript,Jquery,Jquery Ui,Javascript Events,现在我有一个div,它从右向左滑动,然后从右向左滑动回到原来的位置。但总的来说,这并不是我想要的工作方式。我的主要目标是:让用户将鼠标悬停在主div上,然后拉出滑动div。需要技巧的部分如下:如果用户忘记将俯冲向后滑动,我想给它一个时间框架,使其在经过一定时间后自动关闭。以下是我目前的工作代码: 我的javascript函数: $(document).ready(function() { $("#arrow").hover( function(){ $("#inner")
$(document).ready(function() {
$("#arrow").hover(
function(){
$("#inner").stop().animate({marginRight: "0px", opacity: "1px", height: "100px"}, 500 );
},
function(){}
);
});
$("#arrow").click(function(e){
$("#inner").stop().animate({marginRight: "-100px", opacity: "1px", height: "100px"}, 500 );
});
您需要确保使用jQuery的
hover
方法中的第二个函数()
目前,当用户将鼠标悬停在主div上时,您仅对滑出div设置动画。您希望它也在悬停时设置动画
以下是更新的。您需要确保使用jQuery的悬停方法中的第二个函数()
目前,当用户将鼠标悬停在主div上时,您仅对滑出div设置动画。您希望它也在悬停时设置动画
以下是更新后的。在悬停函数中,您可以添加一行,以使用以下行触发单击事件:
setTimeout(function() { $("#arrow").trigger('click'); }, 5000);
5000
是触发单击之前等待的毫秒数。在悬停函数中,您可以使用下面的行添加一行以触发单击事件:
setTimeout(function() { $("#arrow").trigger('click'); }, 5000);
5000
是触发单击之前等待的毫秒数。请参见此处的小提琴:
它使用mouseleave
jquery和delay
。更改延迟中的值以获得所需的时间
$("#arrow").mouseleave(function(){
$("#inner").stop().delay(500).animate({marginRight: "-100px", opacity: "1px", height: "100px"}, 500 );
});
请看这里的小提琴:
它使用mouseleave
jquery和delay
。更改延迟中的值以获得所需的时间
$("#arrow").mouseleave(function(){
$("#inner").stop().delay(500).animate({marginRight: "-100px", opacity: "1px", height: "100px"}, 500 );
});
您需要使用setTimeout()
设置关闭div的延迟。您还需要在打开函数中使用clearTimeout()
在有人鼠标离开时停止自动关闭,然后再次返回:
var timeout;
$("#arrow").hover(
function() {
clearTimeout(timeout); // clear the timer which will close the div, as we now want it open
$("#inner").stop().animate({
marginRight: "0px",
opacity: "1px",
height: "100px"
}, 500);
}, function() {
timeout = setTimeout(function() {
$("#inner").stop().animate({
marginRight: "-100px",
opacity: "1px",
height: "100px"
}, 500);
}, 1000); // close the open div 1 second after mouseout.
}
);
您需要使用设置超时()
设置关闭div的延迟。您还需要在打开函数中使用clearTimeout()
在有人鼠标离开时停止自动关闭div,然后再次返回:
var timeout;
$("#arrow").hover(
function() {
clearTimeout(timeout); // clear the timer which will close the div, as we now want it open
$("#inner").stop().animate({
marginRight: "0px",
opacity: "1px",
height: "100px"
}, 500);
}, function() {
timeout = setTimeout(function() {
$("#inner").stop().animate({
marginRight: "-100px",
opacity: "1px",
height: "100px"
}, 500);
}, 1000); // close the open div 1 second after mouseout.
}
);
这里有一个通过setTimeout函数设置3秒延迟:
jQuery
var cto;
$("#arrow").hover(
function() {
clearTimeout(cto);
$("#inner").stop().animate({
marginRight: "0px",
opacity: "1px",
height: "100px"
}, 500);
}, function() {
cto = setTimeout(function(){$('#arrow').trigger('click')}, 3000);
});
$("#arrow").click(function(e) {
$("#inner").stop().animate({
marginRight: "-100px",
opacity: "1px",
height: "100px"
}, 500);
});
请注意,如果用户移开鼠标,然后将其返回到div,则该框将再次保持打开状态,直到他们离开时3秒倒计时开始。这里有一个通过setTimeout函数设置3秒延迟:
jQuery
var cto;
$("#arrow").hover(
function() {
clearTimeout(cto);
$("#inner").stop().animate({
marginRight: "0px",
opacity: "1px",
height: "100px"
}, 500);
}, function() {
cto = setTimeout(function(){$('#arrow').trigger('click')}, 3000);
});
$("#arrow").click(function(e) {
$("#inner").stop().animate({
marginRight: "-100px",
opacity: "1px",
height: "100px"
}, 500);
});
请注意,如果用户将鼠标移开,然后将其返回到div,则框将再次保持打开状态,直到他们离开,此时3秒倒计时开始。尝试以下操作:
我连接到mouseleave事件并添加了一个setTimeout。如果以后需要取消超时(即,他们重新输入箭头),您可能需要捕获超时。请尝试以下操作:
我连接到mouseleave事件并添加了一个setTimeout。如果以后需要取消超时(即,他们重新输入箭头),则可能需要捕获超时。工作正常,但称为“inner”的滑动div是用户需要输入信息的表单。是否有一种可能的方式,在用户离开名为“inner.Works good”的滑动分区后开始计时,但名为“inner”的滑动分区是用户需要输入信息的表单。是否有一种可能的方式,在用户离开名为“inner.Works good”的滑动分区后开始计时,但该滑动分区名为“inner”是用户需要输入信息的表单。有没有一种可能的方法,在用户离开名为“inner”的滑动div后开始计时。这里有一个新的JSFIDLE:。表单div将保持打开状态,只要鼠标在它上面。工作正常,但该滑动div称为“inner”“是用户需要输入信息的表单。是否有一种可能的方法,在用户离开名为“inner”的滑动div后开始计时。这里有一个新的JSFIDLE:。表单div将保持打开状态,只要鼠标在其上。