[英]jQuery override css hide on mouse out
I have a hidden div that I show when the mouse hovers. 鼠标悬停时会显示一个隐藏的div。
Then when I click the text changes and I want the div to be permanently shown. 然后,当我单击文本更改时,我希望div永久显示。 The problem is that it disappears again when the mouse moves off.
问题是当鼠标移开时它又消失了。
Is there a way in jQuery to override the mouse out hide in the css? jQuery中是否有一种方法可以将鼠标隐藏在CSS中?
Thanks 谢谢
CSS CSS
.saveCompare {
display:none;
margin-left: 10px;
background-color:#BDD455;
color:#ffffff;
padding: 2px 8px;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}
.listingContainer:hover .saveCompare {
display: inline;
}
jQuery jQuery的
$("div.saveCompare").click(function() {
$(this).text('Compare Added');
$(this).show();
return false;
});
Thats probably because of your "display:none" in the ".saveCompare". 那可能是因为您在“ .saveCompare”中的“ display:none”。 The div still has this class.
div仍具有此类。 So its going to hide the div.
因此,它将隐藏div。 Maybe you can write a new class:
也许您可以编写一个新类:
.saveCompareNew {
display:inline;
margin-left: 10px;
background-color:#BDD455;
color:#ffffff;
padding: 2px 8px;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}
And then use this call to remove your old class and add your new class 然后使用此调用删除您的旧课程并添加新课程
.removeClass("saveCompare").addClass("saveCompareNew")
Thats probably no the best solution, but it should work. 那可能不是最好的解决方案,但它应该可以工作。
Before you hide the form on mouseout
do a check 在将
mouseout
隐藏在窗体上之前,请进行检查
$('#yourElement').hover(function(){
//show your form
},function(){
if (!textHasChanged)
//hide your form
});
As far as I know it is not possible to manipulate pseudo-classes in JavaScript (correct me if I'm wrong). 据我所知,不可能在JavaScript中操纵伪类(如果我错了,请纠正我)。 You could go for a all-jQuery solution with sth like this:
您可以使用这样的全jQuery解决方案:
$('.saveCompare').hide(); //you could do this in the CSS as well
$('.listingContainer').hover(function(){
$(this).children('.saveCompare').show(); //on mouse over show child .saveCompare
},function(){
$(this).children('.saveCompare').hide(); //on mouse out hide child .saveCompare
});
$('.saveCompare').click(function(){
$(this).append('<p>Added</p>').parent('.listingContainer').unbind(); //remove parent element's hover handler when clicked and show .saveCompare forever
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.