2017-04-04 18 views
0

我实现了这个真棒codepen到我的网站: https://codepen.io/ccrch/pen/yyarazJQuery的点击目标

$('.display-image') 
.on('change', function(){ 
    $(this).children('img').css({'transform': 'scale('+ $(this).attr('data-scale') +')'}); 
}) 
.on('mouseover', function(){ 
    $(this).children('img').css({'transform': 'scale('+ $(this).attr('data-scale') +')'}); 
}) 
.on('mouseout', function(){ 
    $(this).children('img').css({'transform': 'scale(1)','transition': 'transform .3s ease-out'}); 
}) 
.on('mousemove', function(e){ 
    $(this).children('img').css({'transform-origin': ((e.pageX - $(this).offset().left)/$(this).width()) * 100 + '% ' + ((e.pageY - $(this).offset().top)/$(this).height()) * 100 +'%'}); 
}) 

问题是我指定一个漂亮的滑块对象:当浮油过滤目标 http://kenwheeler.github.io/slick/

而且对象'.display-image'不再注册这些点击事件。我如何着手重新定位这个对象?

回答

0

考虑给滑块一个ID,然后引用它作为$('#id')而不是风格类(这是jQuery如何查找点显示图像)。

+0

在滑块中的图像在for循环中产生;所以我需要有唯一的ID。然后,jquery需要查看每个ID或通配符。这是否使它有所不同? – Tincdawg

+0

通配符应该可以工作。 Ex'$('img [name^=“startsWithSomething”]') – Iceman

+0

感谢冰人 - 但这是行不通的。还有其他建议吗? – Tincdawg

0

我制定了解决方案。为了使代码看的而不必在事件监听器的任何变化,:

$('.display-image').on('click', function() {*code here*}); 

我改成

$(document).on('click', '.display-image', function() {*code here*});