2011-11-05 35 views
4

由于某些原因,单击文档在Chrome中不起作用(closeQuickView未被调用)。event.stopPropagation()在使用jQuery 1.7时不能在chrome中工作

这些元件经由AJAX加载并因此需要有。对()动作(先前.live(),其现在已经过时在jQuery 1.7

这里使用给出的示例:How do I detect a click outside an element?作为基础

$('html').on('click', '.poster:not(.active) .image-effect', function (event) { 

     var obj = $(this).parent(); 

     // If there are no .close spans 
     if (obj.find('.close').length === 0) { 

      // Add the close element by javascript to remain semantic 
      obj.find('.quick-view').append('<span class="close">&times;</span>'); 
     } 

     // Close any open Quick Views 
     closeQuickView(); 

     // Add the active class (controls opacity) 
     obj.addClass('active'); 

     // Fade in the Quick View 
     obj.find('.quick-view').fadeIn(200, 'easeInOutQuint'); 

     event.preventDefault(); 
     event.stopPropagation(); 

    }); 

    $('html').on('click', '.active', function() { 
     return false; 
    }); 

    $('html').on('click', '.close', function() { 
     closeQuickView(); 
    }); 

    $('html').on('click', '.quick-view', function (event) { 
     event.stopPropagation(); 
    }); 

    // Close the QuickView with a button 
    $('html').on('click', function() { 
     closeQuickView(); 
    }); 

    function closeQuickView() { 
     $('.poster').removeClass('active'); 
     $('.quick-view').fadeOut(200, 'easeInOutQuint'); 
    } 

我的标记如下:

<figure class="grid_2 box poster"> 
    <a class="image-effect" href="#"> 
     <img class="colour" src="path/to/image" /> 
     <img class="bw" src="path/to/image" /> 
    </a> 
    <div class="quick-view"> 

     Content 

    </div> 
</figure> 
+0

数字被封装在AJAX加载的主题#content div中。我添加了一个内部包装div,清除了缓存,它现在似乎正在工作:S – Craig

回答

7

尝试event.stopImmediatePropagation

Refer documentation

+1

谢谢,我不知道这一点。我应该使用哪个事件?都?我会试验。 – Craig

+1

谢谢你.. stoppropagation没有为我工作..这件事情很好..再次感谢 –

0

jquery 1.6.4遭受同样的错误。使用stopImmediatePropagation解决。

相关问题