[英]Show Div on Hover
I have the following JavaScript (with jQuery) 我有以下JavaScript(使用jQuery)
$(function() {
$(".btnDesc").click(function() {
$("#desc").slideToggle("slow");
$(this).toggleClass("active");
});
When I change .click(function()
to .hover(function()
, as expected, hovering over the link with class="btnDesc"
shows the div instead of clicking it, however, I would like to make it show when you stop hovering over the link, the div stays until you click a hide button. With it how I have it, once you stop hovering over the link, the div slides back up. 当我改变
.click(function()
来.hover(function()
符合市场预期,悬停在该链接class="btnDesc"
显示在div不是单击它,但是,我想使其显示当你停止将鼠标悬停在链接上时,div会一直保留,直到您单击“隐藏”按钮为止。使用它的方式,一旦停止将鼠标悬停在链接上,div就会向后滑动。
您需要使用mouseover
而不是hover
,它会捕获鼠标在链接上移动的事件,但不会在鼠标移离链接时绑定到该事件。
The hover function in jquery requires two functions within it - the mouseover and mouseout functions... eg jQuery中的悬停功能需要其中的两个功能-mouseover和mouseout功能...例如
$(".btnDesc").hover(
function() {
// code to run when mouse hovers in
$("#desc").show("slow");
$(this).toggleClass("active");
},
function() {
// code to run when mouse hovers out
$("#desc").hide("slow");
$(this).toggleClass("active");
}
);
That will show your desc element when you hover over, and hide it when you hover out. 当您将鼠标悬停在上方时,它将显示desc元素;当您将鼠标悬停在其上方时,它将隐藏它。 The jquery documentation on this function is pretty good too if you get stuck.
如果遇到问题,关于此功能的jquery文档也相当不错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.