Hack:使用 jQuery 禁用单击
我正在破解一个画廊插件,我想在其中禁用缩略图的单击事件并将其替换为悬停事件。
这就是我所做的: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想使用 jQuery 的 unbind 方法来解除点击事件的绑定。调用插件后必须调用它。例如:
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.:
您可以尝试解除
click
方法的绑定,然后将原始函数绑定到hover
。如果您无法获得原始函数,您可以通过查看控制台返回的内容来获得它,如果您抛出:
然后您抓住该函数并执行以下操作:
编辑:
Here 是我所使用的示例
“theValueYouGotInTheConsole”
,在图像中我正在访问 click 属性,然后“4”是存储函数的位置。如果您不想硬编码该值,您可以执行以下操作:
You could try to unbind the
click
method and then bind the original function to thehover
.If you can't get the original function you can get it by seeing what the console returns if you throw:
then you grab that function and do:
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: