自 jQuery 1.7 起,UI 选项卡上的悬停意图事件不会触发

发布于 2024-12-17 17:32:24 字数 2089 浏览 3 评论 0原文

自从我升级到 jQuery 1.7 以来,hoverIntent 事件在 UI 选项卡上不再起作用。从 jQuery 1.7 开始,选项卡立即切换,而不是使用悬停意图。

这是我用来初始化 UI 选项卡的代码:

$("#featured").tabs({event: "hoverintent"}).tabs({fx:{opacity: "toggle", duration: 250}}).tabs("rotate", 7000, true);
      $("#featured").hover(  
        function() {  
          $("#featured").tabs("rotate",0,true);  
        },  
        function() {  
          $("#featured").tabs("rotate",7000,true);  
        }  
    );

这是我包含在页面中的悬停意图事件的 js:

var cfg = ($.hoverintent = {
  sensitivity: 7,
  interval: 100
});

$.event.special.hoverintent = {
  setup: function() {
    $(this).bind("mouseover", jQuery.event.special.hoverintent.handler);
  },
  teardown: function() {
    $(this).unbind("mouseover", jQuery.event.special.hoverintent.handler);
  },
  handler: function(event) {
    event.type = "hoverintent";
    var self = this,
      args = arguments,
      target = $(event.target),
      cX, cY, pX, pY;


    function track(event) {
      cX = event.pageX;
      cY = event.pageY;
    };
    pX = event.pageX;
    pY = event.pageY;
    function clear() {
      target.unbind("mousemove", track).unbind("mouseout", arguments.callee);
      clearTimeout(timeout);
    }
    function handler() {
      if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
        clear();
        jQuery.event.handle.apply(self, args);
      } else {
        pX = cX; pY = cY;
        timeout = setTimeout(handler, cfg.interval);
      }
    }
    var timeout = setTimeout(handler, cfg.interval);
    target.mousemove(track).mouseout(clear);
    return true;
  }
};

这里似乎有一个修复程序(尽管针对 UI Accordion): com/jquery/jquery-ui/commit/f0f54e38d8eab613d7ea25d698b81126e5263d83#diff-0" rel="nofollow">https://github.com/jquery/jquery-ui/commit/f0f54e38d8eab613d7ea25d698b81126e5263d83#diff-0

查看演示:http://jqueryui.com/demos/accordion/hoverintent.html

但是,我不确定如何让hoverIntent再次工作。上面的代码需要进行哪些更改?很高兴获得任何帮助!

since I've upgraded to jQuery 1.7, the hoverIntent event does not work anymore on UI Tabs. Since jQuery 1.7, the tab switches instantly instead of using hoverIntent.

Here is the code, I used to initialize UI Tabs:

$("#featured").tabs({event: "hoverintent"}).tabs({fx:{opacity: "toggle", duration: 250}}).tabs("rotate", 7000, true);
      $("#featured").hover(  
        function() {  
          $("#featured").tabs("rotate",0,true);  
        },  
        function() {  
          $("#featured").tabs("rotate",7000,true);  
        }  
    );

This is the js for hoverIntent event I included in my page:

var cfg = ($.hoverintent = {
  sensitivity: 7,
  interval: 100
});

$.event.special.hoverintent = {
  setup: function() {
    $(this).bind("mouseover", jQuery.event.special.hoverintent.handler);
  },
  teardown: function() {
    $(this).unbind("mouseover", jQuery.event.special.hoverintent.handler);
  },
  handler: function(event) {
    event.type = "hoverintent";
    var self = this,
      args = arguments,
      target = $(event.target),
      cX, cY, pX, pY;


    function track(event) {
      cX = event.pageX;
      cY = event.pageY;
    };
    pX = event.pageX;
    pY = event.pageY;
    function clear() {
      target.unbind("mousemove", track).unbind("mouseout", arguments.callee);
      clearTimeout(timeout);
    }
    function handler() {
      if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
        clear();
        jQuery.event.handle.apply(self, args);
      } else {
        pX = cX; pY = cY;
        timeout = setTimeout(handler, cfg.interval);
      }
    }
    var timeout = setTimeout(handler, cfg.interval);
    target.mousemove(track).mouseout(clear);
    return true;
  }
};

There seems to be a fix (for UI Accordion though) here: https://github.com/jquery/jquery-ui/commit/f0f54e38d8eab613d7ea25d698b81126e5263d83#diff-0

See demo: http://jqueryui.com/demos/accordion/hoverintent.html

However, I'm not sure, how to get hoverIntent working again. What changes have to be made to the code above? Glad for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼波传意 2024-12-24 17:32:24

将 jQuery 更新到 v1.7.1 解决了这个问题。

Updating jQuery to v1.7.1 solved the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文