简体   繁体   English

jQuery单击叠加效果

[英]jQuery Click on Overlay Effect

I'm trying to use a jQuery effect as spotted here on StackOverflow ( jQuery image hover color overlay ) on a list in my HTML template. 我正在尝试使用HTML模板中列表上StackOverflow( jQuery图像悬停颜色叠加层 )上的jQuery效果。 The effect works, but unfortunately the link no longer clicks through to the next page. 效果有效,但不幸的是,链接不再单击指向下一页。

The HTML Markup is... HTML标记是...

<ul class="rollover-effect">
    <li><a href="page.html"><img src="image.jpg" alt="Image Title" /></a></li>
    <li><a href="page.html"><img src="image.jpg" alt="Image Title" /></a></li>      
    <li><a href="page.html"><img src="image.jpg" alt="Image Title" /></a></li>
</ul>

...and my jQuery reads... ...而我的jQuery读取...

jQuery('ul.rollover-effect a').bind('mouseover', function(){
    jQuery(this).parent('li').css({position:'relative'});
    var img = jQuery(this).children('img');
    jQuery('<div />').text(' ').css({
        'height': img.height(),
        'width': img.width(),
        'background-color': 'black',
        'position': 'absolute',
        'top': 0,
        'left': 0,
        'opacity': 0.0,
        'cursor': 'pointer'
    }).bind('mouseout', function(){
        jQuery(this).fadeOut(200, function(){
            jQuery(this).remove();
        });
    }).insertAfter(this).animate({
        'opacity': 0.40
    }, 200);
});

Can anybody see or do they know why this might be? 谁能看到或知道为什么会这样吗? I want to be able to click through to the next page. 我希望能够单击进入下一页。 It's bugging me! 烦我! Thanks. 谢谢。

So far as I can tell quickly without any testing, the click events are being captured by your overlay, and not bubbled up to the link element because the overlay is not a child of the link. 据我所知,无需任何测试即可迅速知道,单击事件是由叠加层捕获的,并且不会冒泡到链接元素,因为叠加层不是链接的子级。

To compensate, you could bind a click handler to the overlay which triggers a click event on the link. 为了补偿,您可以将点击处理程序绑定到叠加层,该叠加层会触发链接上的点击事件。

jQuery('ul.rollover-effect a').bind('mouseover', function(){
  var $this = jQuery(this);
  $this.parent('li').css({position:'relative'});
  var img = $this.children('img');
  jQuery('<div />').text(' ').css({
      'height': img.height(),
      'width': img.width(),
      'background-color': 'black',
      'position': 'absolute',
      'top': 0,
      'left': 0,
      'opacity': 0.0,
      'cursor': 'pointer'
  }).bind('mouseout', function(){
      jQuery(this).fadeOut(200, function(){
          jQuery(this).remove();
      });
  }).bind('click', function(){
      $this.click();
  }).insertAfter(this).animate({
      'opacity': 0.40
  }, 200);
});

Your code is working fine for me (Tested on firefox & ie8 ). 您的代码对我来说工作正常(在firefoxie8上测试)。

Am doubted, since you have pointed to same page for three hyperlinks. 怀疑,因为您已指向同一页面的三个超链接。 This might you confused to see that it is not redirecting to next page. 您可能会感到困惑,因为它没有重定向到下一页。

Change the hyperlink filename for three links and test it, once again. 更改三个链接的超链接文件名,然后再次对其进行测试。

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

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