为什么鼠标悬停和单击不总是有效? [英] why does the hover and click not always work?
本文介绍了为什么鼠标悬停和单击不总是有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的小提琴
几乎完全可以正常工作,但有时mouseenter,mouseleave,click函数(.item)并不总是有效-需要单击以使其重新开始工作吗?为什么会这样-这是我的代码-
Pretty much working perfectly apart from sometimes mouseenter, mouseleave, click function (.item) doesn't always work - and needs to be clicked for it to start working again? why is this - here is my code -
$(document).ready(function () {
$('.timelineTile').click(function (evt) {
evt.stopPropagation();
$('.timelineTile').not(this).removeClass('clicked').find('.pull_down_content').height(0);
$(this).toggleClass('clicked');
if(!$('.timelineTile').hasClass("clicked")){
$(this).children('.pull_down_content').height(0);
}
}); });
$(document).click(function () {
$('.timelineTile').removeClass('clicked');
$('.pull_down_content').height(0);
$('.inner').stop().css({'display': 'none'}, 300);
});
$(document).ready(function () {
$('.timelineTile').children('.item').on('mouseenter mouseleave click', function(e) { e.stopPropagation();
if ($(this).parent('.timelineTile').hasClass("clicked")) {
if (!$(this).data('clicked')) {
var Height = e.type==='mouseenter' ? '90px' : e.type==='click' ? '250px' : '0px';
$(this).siblings('.pull_down_content').stop().animate({'height': Height}, 300);
$(this).siblings('.pull_down_content').children('.inner').css({'display': 'block'}, 300);
if (e.type==='click') $(this).data('clicked', true);
}else{
if (e.type==='click') {
$(this).data('clicked', false);
$(this).siblings('.pull_down_content').stop().animate({'height': '0px'}, 300);
$(this).siblings('.pull_down_content').children('.inner').css({'display': 'none'}, 300);
}
}
}
});
});
我不确定是否与此有关?
I'm not sure if its something to do with this?
if(!$('.timelineTile').hasClass("clicked")){
$(this).children('.pull_down_content').height(0);
}
推荐答案
尝试替换
$('.timelineTile').not(this).removeClass('clicked').find('.pull_down_content').height(0);
与此
$('.timelineTile').not(this).removeClass('clicked').find('.pull_down_content').height(0).end().find('.item').data('clicked',false);
这篇关于为什么鼠标悬停和单击不总是有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文