Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 设置鼠标输入和鼠标输出超时,不';I don’我什么时候走?_Javascript_Jquery_Settimeout_Mouseleave - Fatal编程技术网

Javascript 设置鼠标输入和鼠标输出超时,不';I don’我什么时候走?

Javascript 设置鼠标输入和鼠标输出超时,不';I don’我什么时候走?,javascript,jquery,settimeout,mouseleave,Javascript,Jquery,Settimeout,Mouseleave,var时间=2000; 变量t; var-th; var hover=函数($element){ 清除超时(th); $element.parents('.tbody').find('.hotel').removeClass('hover active'); $element.find('.hotel').addClass('hover'); } var hoverOut=函数($element){ 清除超时(th); $element.find('.hotel').removeClass('h

var时间=2000;
变量t;
var-th;
var hover=函数($element){
清除超时(th);
$element.parents('.tbody').find('.hotel').removeClass('hover active');
$element.find('.hotel').addClass('hover');
}
var hoverOut=函数($element){
清除超时(th);
$element.find('.hotel').removeClass('hover');
}
var enable=函数($element){
$element.parents('.tbody').find('.hotel').removeClass('active');
$element.find('.hotel').removeClass('hover').addClass('active');
}
$(函数(){
$('.price')。在('mouseenter',function()上{
var$this=$(this);
th=设置超时(函数(){
悬停($this);
},时间);
}).on('mouseleave',function(){
var$this=$(this);
清除超时(th);
th=设置超时(悬停($this),时间)
});
$('.price')。在('click',function()上{
启用($(此));
});
});
.price{
填充:1em;
边框:1px实心;
}
.酒店{
显示:无;
边缘顶部:10px;
边框:1px实心;
填充:1em;
}
霍弗酒店{
显示:块;
}
.active酒店{
显示:块;
背景:黑色;
颜色:白色;
}

盘旋我
我是一家旅馆

您正在调用函数,而不是传递函数引用。您可以使用
setTimeout
回调函数调用带有参数的函数

使用
hoverOut($this)
作为
setTimeout
的回调函数时,会立即调用
hoverOut

// See this section
th = setTimeout(function () {
    hoverOut($this)
}, time)
演示

var时间=2000;
变量t;
var-th;
var hover=函数($element){
清除超时(th);
$element.parents('.tbody').find('.hotel').removeClass('hover active');
$element.find('.hotel').addClass('hover');
}
var hoverOut=函数($element){
清除超时(th);
$element.find('.hotel').removeClass('hover');
}
var enable=函数($element){
$element.parents('.tbody').find('.hotel').removeClass('active');
$element.find('.hotel').removeClass('hover').addClass('active');
}
$(函数(){
$('.price')。在('mouseenter',function()上{
var$this=$(this);
th=设置超时(函数(){
悬停($this);
},时间);
}).on('mouseleave',function(){
var$this=$(this);
清除超时(th);
th=设置超时(函数(){
悬停($this)
},时间)
});
$('.price')。在('click',function()上{
启用($(此));
});
});
.price{
填充:1em;
边框:1px实心;
}
.酒店{
显示:无;
边缘顶部:10px;
边框:1px实心;
}
霍弗酒店{
显示:块;
}
.active酒店{
显示:块;
背景:黑色;
颜色:白色;
}

盘旋我
我是一家旅馆

您正在调用函数,而不是传递函数引用。您可以使用
setTimeout
回调函数调用带有参数的函数

使用
hoverOut($this)
作为
setTimeout
的回调函数时,会立即调用
hoverOut

// See this section
th = setTimeout(function () {
    hoverOut($this)
}, time)
演示

var时间=2000;
变量t;
var-th;
var hover=函数($element){
清除超时(th);
$element.parents('.tbody').find('.hotel').removeClass('hover active');
$element.find('.hotel').addClass('hover');
}
var hoverOut=函数($element){
清除超时(th);
$element.find('.hotel').removeClass('hover');
}
var enable=函数($element){
$element.parents('.tbody').find('.hotel').removeClass('active');
$element.find('.hotel').removeClass('hover').addClass('active');
}
$(函数(){
$('.price')。在('mouseenter',function()上{
var$this=$(this);
th=设置超时(函数(){
悬停($this);
},时间);
}).on('mouseleave',function(){
var$this=$(this);
清除超时(th);
th=设置超时(函数(){
悬停($this)
},时间)
});
$('.price')。在('click',function()上{
启用($(此));
});
});
.price{
填充:1em;
边框:1px实心;
}
.酒店{
显示:无;
边缘顶部:10px;
边框:1px实心;
}
霍弗酒店{
显示:块;
}
.active酒店{
显示:块;
背景:黑色;
颜色:白色;
}

盘旋我
我是一家旅馆

您正在调用函数,而不是传递函数引用。您可以使用
setTimeout
回调函数调用带有参数的函数

使用
hoverOut($this)
作为
setTimeout
的回调函数时,会立即调用
hoverOut

// See this section
th = setTimeout(function () {
    hoverOut($this)
}, time)
演示

var时间=2000;
变量t;
var-th;
var hover=函数($element){
清除超时(th);
$element.parents('.tbody').find('.hotel').removeClass('hover active');
$element.find('.hotel').addClass('hover');
}
var hoverOut=函数($element){
清除超时(th);
$element.find('.hotel').removeClass('hover');
}
var enable=函数($element){
$element.parents('.tbody').find('.hotel').removeClass('active');
$element.find('.hotel').removeClass('hover').addClass('active');
}
$(函数(){
$('.price')。在('mouseenter',function()上{
var$this=$(this);
th=设置超时(函数(){
悬停($this);
},时间);
}).on('mouseleave',function(){
var$this=$(this);
清除超时(th);
th=设置超时(函数(){
悬停($this)
},时间)
});
$('.price')。在('click',function()上{
启用($(此));
});
});
.price{
填充:1em;
边框:1px实心;
}
.酒店{
显示:无;
边缘顶部:10px;
边框:1px实心;
}
霍弗酒店{
显示:块;
}
.active酒店{
显示:块;
背景:黑色;
颜色:白色;
}

盘旋我
我是一家旅馆

您正在调用函数,而不是传递函数引用。您可以使用
setTimeout
回调函数调用带有参数的函数

使用
hoverOut($this)
作为
set的回调函数时