jquery - 使用单击功能禁用 jquery 悬停功能

标签 jquery click hover

我们有一个画廊,当您将光标悬停在图像 div 上时,其标题会淡出。我们的下一步是添加一个显示所有标题的按钮,这样人们就可以滚动和阅读,而无需将光标遍布屏幕。

创建 showall 函数很容易,但是当光标经过任何照片时,悬停函数会触发,并且该图像上的标题会消失。

有没有一种简单的方法可以让 showall 功能在 showall 处于事件状态时禁用悬停功能?

我们的基本jquery代码如下,.tease是标题:

$('.tease').hide();
$('.img33, .img40, .img50, .img60').hover(
    function(){ $(this).children('.tease').fadeIn('900'); },
    function(){ $(this).children('.tease').fadeOut('2500'); }
);

每个图像的基本 html:

<div class="img33">
<img src="../dir/someimage.jpg">
<div class="tease">Tease copy</div>
</div>

最佳答案

您可以定义一个在悬停函数中检查的全局变量。

例如

var hoverEnabled = true;

$('.tease').hide();
$('.img33, .img40, .img50, .img60').hover(
    function(){ if(hoverEnabled) $(this).children('.tease').fadeIn('900'); },
    function(){ if(hoverEnabled) $(this).children('.tease').fadeOut('2500'); }
);

$('#showAllButton').click(function() {
    $('.tease').show();
    hoverEnabled = false;
}

或者,您可以在 showall 函数中使用 .bind() 和事件名称(例如hover.showTease)和 .unbind() 绑定(bind)悬停事件。

关于jquery - 使用单击功能禁用 jquery 悬停功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13358202/

相关文章:

javascript - 使用 jQuery,如何将 "scroll counter"添加到我的页面?

javascript - 尝试让粘性栏悬停在滚动页脚上方

javascript - react : How could we detect user click on canvas?

Delphi TPageControl 不响应选项卡上的点击

javascript - CSS/HTML5 :hover state remains after drag and drop

jquery - 用 fancybox 显示图像

c++ - 如何在 Linux 上获取 C++ 代码块的时钟滴答? clock() 结果没有意义。

html - 为什么我的表 tr td :hover only work for the th header row? 而不是任何其他行?

css - 元素不失去焦点

javascript - Jquery iCheck 在列表输入中不起作用