Hack:使用 jQuery 禁用单击

发布于 2025-01-07 15:09:07 字数 1180 浏览 0 评论 0原文

我正在破解一个画廊插件,我想在其中禁用缩略图的单击事件并将其替换为悬停事件。

这就是我所做的: http://jsbin.com/enezol/3

$(function() {

  var galleries = $('.ad-gallery').adGallery();


  $('.ad-thumb-list a').hover(function() {
    $(this).click();
  });

   $('.ad-thumb-list a').click(function() {
    return false;
  });


});

该插件不允许我设置要使用的事件。因此,我不会从他们的代码中更改它,而是在其之上添加一些调整。

所以我想禁用“缩略图”的点击事件,而只使用“悬停”事件。

有什么想法和想法吗?只要满足我的要求,我也愿意接受其他方法。

谢谢你!


尝试实现 Steph Skardal 和 Nicosunshine 建议:

var thumbs = $('.ad-thumb-list a'),
    oldfunction = thumbs.data("events").click["function () {  context.showImage(i); context.slideshow.stop(); return false; }"];

thumbs.unbind("click").hover(oldFunction);

编辑:我的解决方案:

我使用 return false 来限制它访问该 url,但它不限制调用该函数。还有其他想法吗?

 var galleries = $('.ad-gallery').adGallery();

    var thumbs = $('.ad-thumb-list a');

    thumbs .hover(
        function () {
            $(this).click();
        },
        function () {

        }
    );

    thumbs.click( function () { return false; });

I'm hacking a gallery plugin where I want to disable the click event for the thumbnail and replace it with a hover event.

This is what I did: http://jsbin.com/enezol/3

$(function() {

  var galleries = $('.ad-gallery').adGallery();


  $('.ad-thumb-list a').hover(function() {
    $(this).click();
  });

   $('.ad-thumb-list a').click(function() {
    return false;
  });


});

The plugin doesn't allow me to set event to use. So Instead of changing it from their code, I'll just add a little tweak on top of it.

So I want to disable the click event for the 'thumbnail' and just use 'hover' event instead.

Any got and ideas? I'm also open to other approach as long as it meets my requirement.

Thank You!


Trying to implement Steph Skardal and Nicosunshine suggestion:

var thumbs = $('.ad-thumb-list a'),
    oldfunction = thumbs.data("events").click["function () {  context.showImage(i); context.slideshow.stop(); return false; }"];

thumbs.unbind("click").hover(oldFunction);

edit: My Solution:

I use return false to restrict it from going to the url but it does not restrict in calling the function. Any alternative ideas?

 var galleries = $('.ad-gallery').adGallery();

    var thumbs = $('.ad-thumb-list a');

    thumbs .hover(
        function () {
            $(this).click();
        },
        function () {

        }
    );

    thumbs.click( function () { return false; });

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

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

发布评论

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

评论(2

纵山崖 2025-01-14 15:09:07

您想使用 jQuery 的 unbind 方法来解除点击事件的绑定。调用插件后必须调用它。例如:

$('.ad-thumb-list a').unbind('click');

You want to use jQuery's unbind method, to unbind the click event. It will have to be called after the plugin is called. E.g.:

$('.ad-thumb-list a').unbind('click');
爱情眠于流年 2025-01-14 15:09:07

您可以尝试解除click方法的绑定,然后将原始函数绑定到hover

如果您无法获得原始函数,您可以通过查看控制台返回的内容来获得它,如果您抛出:

$('.ad-thumb-list a').data("events").click; //name of the property that has the function

然后您抓住该函数并执行以下操作:

var thumbs = $('.ad-thumb-list a'),
    oldfunction = thumbs.data("events").click["theValueYouGotInTheConsole"];

thumbs.unbind("click")
      .hover(oldFunction);

编辑:

Here 是我所使用的示例“theValueYouGotInTheConsole”,在图像中我正在访问 click 属性,然后“4”是存储函数的位置。

如果您不想硬编码该值,您可以执行以下操作:

var dataEvents = thumbs.data("events").click,
    oldFunction;

for(var functionEvent in dataEvents) {
     oldFunction = dataEvents[functionEvent];
     break; //I'm assuming there's only one event
}

You could try to unbind the click method and then bind the original function to the hover.

If you can't get the original function you can get it by seeing what the console returns if you throw:

$('.ad-thumb-list a').data("events").click; //name of the property that has the function

then you grab that function and do:

var thumbs = $('.ad-thumb-list a'),
    oldfunction = thumbs.data("events").click["theValueYouGotInTheConsole"];

thumbs.unbind("click")
      .hover(oldFunction);

Edit:

Here is an example of what I ment with "theValueYouGotInTheConsole", in the image I'm accessing the click property, and then the "4" is where the function is stored.

If you don't want to hardcode the value you can do:

var dataEvents = thumbs.data("events").click,
    oldFunction;

for(var functionEvent in dataEvents) {
     oldFunction = dataEvents[functionEvent];
     break; //I'm assuming there's only one event
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文