2013-09-23 38 views
0

所以我一直在玩这个游戏一段时间,但无法从绑定的点击事件中触发jqzoomed元素。将点击事件绑定到jqzoom以启动fancybox

HTML:

<div class="product-clicktozoom-image"> 
    <div class="product-clicktozoom-image-main"> 
     <a href="http://example.com/image.jpg" class="jqzoom" title="Image" rel="gall"><img itemprop="image" id="mainimage" src="http://exampe.com/image.jpg" alt="Image" title="Image"/></a> 
    </div> 
</div> 

JS:

jQuery(document).load(function() { 
    jQuery('#mainimage').bind('click',function(){ 
      var fancyImage = jQuery('#mainimage').attr('src');    
      jQuery.fancybox.open(fancyImage); 
    }); 
}); 

jqzoom创造一些额外的div所以最终的页面结构实际上是这样的:

<div class="product-clicktozoom-image-main"> 
    <a href="example.com/image.jpg" class="jqzoom" title="" rel="gall" style="outline-style: none; text-decoration: none;"> 
     <div class="zoomPad"> 
      <img itemprop="image" id="mainimage" src="http://example.com/image.jpg" alt="Image" title="Image" style="opacity: 1;"> 
       <div class="zoomPup" style="display: none; top: 105px; left: 145px; width: 126px; height: 126px; position: absolute; border-width: 1px;"></div> 
       <div class="zoomWindow" style="position: absolute; z-index: 5001; cursor: default; left: 0px; top: 0px; display: none;"> 
        <div class="zoomWrapper" style="border-width: 1px; width: 355px; cursor: crosshair;"> 
         <div class="zoomWrapperTitle" style="width: 100%; position: absolute; display: none;"></div> 
         <div class="zoomWrapperImage" style="width: 100%; height: 355px;"> 
          <img src="http://example.com/image.jpg" style="position: absolute; border: 0px; display: block; left: -411.26760563380276px; top: -298.5915492957746px;"> 
         </div> 
        </div> 
       </div> 
       <div class="zoomPreload" style="visibility: hidden; top: 156px; left: 132.5px; position: absolute;">Loading zoom</div> 
     </div> 
    </a> 
</div> 

我有tr ied将click事件绑定到#mainimage,以及zoomPad类和zoomWrapperImage元素中的img,因为当您将鼠标悬停在图像上时,这看起来是最重要的元素。

我想要做的就是打开fancybox中的完整图像,如果他们点击缩放(当前zoomover发生在鼠标悬停)。我知道fancybox.open(fancyImage);工作,我可以直接在控制台中直接在点击功能中运行代码,我无法从点击事件本身触发它。

帮助!

+0

你可能有,如果你想在这方面帮助,很插件特定的,问题创造的jsfiddle。 [这是一个预装配fancybox和jqzoom的小提琴](http://jsfiddle.net/TBfZ4/)让你开始。如你所愿自定义和'更新',然后编辑你的问题,并发布其他人的网址。请注意外部资源手风琴 - 这是您为其他js指定CDN的地方(注意:不是http:) – gibberish

回答

2

事实证明,这是最终很简单,单击事件需要对.zoomPad结合,我在的地方(文件)使用window.load。就绪为确保所有的元素都被加载。

最后JS:

jQuery(window).load(function() { 
    jQuery('.zoomPad').bind('click',function(){ 
      var fancyImage = jQuery('.zoomWrapperImage img').attr('src');  
      jQuery.fancybox.open([{href : fancyImage}], {closeClick : true}); 
    }); 
}); 
相关问题