【发布时间】:2014-03-02 20:28:49
【问题描述】:
所以我正在尝试在我的网站 http://www.beautracare.com/ 上为购物车创建一个下拉菜单,到目前为止,如果我将鼠标悬停在购物车上,您会看到一个下拉菜单淡入,但过了一段时间它会超时并淡出如果您仍然将鼠标悬停在购物车下拉菜单上。我尝试创建一个 setTimeout 并在将鼠标悬停在下拉菜单上时将其清除,但它没有响应。我还尝试在 Jquery 中使用下拉悬停功能,但它似乎并没有触发。请帮忙,谢谢。 jQuery代码如下:
jQuery(document).ready(function() {
var timer;
//get all link with class panel
$('a.panel').click(function () {
//reset and highlight the clicked link
$('a.panel').removeClass('selected');
$(this).addClass('selected');
//grab the current item, to be used in resize function
current = $(this);
//scroll it to the destination
$('#wrapper').scrollTo($(this).attr('href'), 800);
//cancel the link default behavior
return false;
});
$('.wsite-nav-cart').hover(
function() {
if ($("#wsite-mini-cart").css("display") == 'none'){
$("#wsite-mini-cart").fadeIn();
timer = window.setTimeout(function() {$("#wsite-mini-cart").fadeOut(); }, 1500);
}
}, function() {
}
);
$("#wsite-mini-cart").hover(
function() {
if (timer) {
window.clearTimeout(timer);
}
$("#wsite-mini-cart").css({'display':'block','opacity':1});
}, function() {
timer = window.setTimeout(function() {$("#wsite-mini-cart").fadeOut(); }, 1500);
}
);
$('.wsite-nav-cart').click(function () {
if ( $(this).attr("id")){
$("#wsite-mini-cart").fadeOut();
$(this).removeAttr('id');
} else {
$("#wsite-mini-cart").fadeIn();
$(this).attr('id', 'active');
}
//cancel the link default behavior
return false;
});
【问题讨论】:
标签: jquery hover mouseover cleartimeout