【问题标题】:jquery-ias jQuery doesn't work for loaded itemsjquery-ias jQuery 不适用于加载的项目
【发布时间】:2018-02-18 02:13:03
【问题描述】:

这就是问题所在,我知道对于新项目我们应该添加渲染事件,这是我的代码,但 jQuery 仍然不适用于新项目,我做错了什么?

$( document ).ready(function() {
$('.dwn').hover(function() {
  $(this).parent().siblings().css({
    'opacity': '0.3'
  })
}, function() {
  $('.view').css({
    'opacity': '1'
  })
});
});

渲染:

 ias.on('rendered', function(items) {
    var $items = $(items);
    $items.each(function() {
    $('.dwn').hover(function() {
      $(this).parent().siblings().css({
        'opacity': '0.3'
      })
    }, function() {
      $('.view').css({
        'opacity': '1'
      })
    });
    });
    });

感谢您的帮助!

【问题讨论】:

    标签: jquery jquery-ias


    【解决方案1】:

    您可以在包含您想要在悬停时执行某些操作的项目的元素上使用事件侦听器。最大和通用的处理程序可以是 $('html')。您必须将 .hover() 分解为两个事件侦听器。修改代码如下:

    $(document).ready(function() {
      $('html').on('mouseover', '.dwn', function() {
        $(this).parent().siblings().css({
          'opacity': '0.3'
        });
      });
      $('html').on('mouseout', '.dwn', function() {
        $('.view').css({
          'opacity': '1'
        });
      });
    });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-09
      • 2014-04-28
      • 1970-01-01
      • 2020-10-08
      相关资源
      最近更新 更多