简体   繁体   English

jQuery-单击div下面的图像

[英]jquery - clicking an image underneath a div

I have a plugin which creates a lens over an image. 我有一个可以在图像上方创建镜头的插件。 But cannot make the image clickable when underneath the lens 但是在镜头下方时无法使图像可点击

I created this on jsfiddle to help illustrate the problem http://jsfiddle.net/F9GT5/2/ 我是在jsfiddle上创建的,以帮助说明问题http://jsfiddle.net/F9GT5/2/

I need to be able to make the image clickable to then perform a set of actions. 我需要使图像可点击才能执行一组操作。

I have seen it done on some sites such as this here http://www.starplugins.com/cloudzoom 我已经在某些网站(例如http://www.starplugins.com/cloudzoom)上看到了它

 $('#myCloudZoom').bind('click',function(){       // Bind a click event to a Cloud Zoom instance.
        var cloudZoom = $(this).data('CloudZoom');   // On click, get the Cloud Zoom object,
        cloudZoom.closeZoom();                       // Close the zoom window (from 2.1 rev 1211291557)
        $.fancybox.open(cloudZoom.getGalleryList()); // and pass Cloud Zoom's image list to Fancy Box.
        return false;
    });

This problem has been driving me nuts for a couple of days now, with the cloudzoom plugin, it seems like they are clicking through the lens to the image below. 有了cloudzoom插件,这个问题已经让我发疯了几天,似乎他们正在通过镜头单击下面的图片。 But as shown in the code above, the click even is bound to the image, but when you inspect element, you get the lens over the top of the image 但是,如上面的代码所示,单击甚至绑定到图像,但是当您检查元素时,会将镜头放在图像的顶部

Has anyone any ideas on how to tackle this problem? 有谁对解决这个问题有任何想法吗?

Using your plugin, store the selector for the image in the div somehow: 使用您的插件,以某种方式将图像的选择器存储在div中:

//Inside the plugin, creating the lens; add attribute for image
$("<div>").data('image', this)
//Then bind a click event to the div to trigger a click on the image:
   .click(function () {
      $(this).data('image').trigger('click');
   });

I'm not sure if I understood your problem, but I think that what you want is to add the "click" event to your "lens" div: 我不确定我是否理解您的问题,但是我认为您想要的是将“ click”事件添加到“ lens” div:

$(".lens").click(function(){
alert("click lens");    
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM