Javascript 如何将鼠标的currentTarget传递到timelineMax函数中
所以我试图创建一个可重用的函数,我的页面上的每个.featured图像都使用这个函数。如果我不使用主干事件:我只编写注释掉的代码,它就可以工作。如何模拟注释代码获取事件imageOver和imageOutJavascript 如何将鼠标的currentTarget传递到timelineMax函数中,javascript,backbone.js,gsap,Javascript,Backbone.js,Gsap,所以我试图创建一个可重用的函数,我的页面上的每个.featured图像都使用这个函数。如果我不使用主干事件:我只编写注释掉的代码,它就可以工作。如何模拟注释代码获取事件imageOver和imageOut app.newsroomPageElementView = Backbone.View.extend({ events: { 'mouseenter .featured-image': 'imageOver', 'mouseleave .featured-i
app.newsroomPageElementView = Backbone.View.extend({
events: {
'mouseenter .featured-image': 'imageOver',
'mouseleave .featured-image': 'imageOut'
},
initialize: function () {
$(".featured-image").each(function(index, element){
var tl = new TimelineLite({paused:true});
tl.to(element, 0.2, {opacity:.9, scale:.9})
.to(element, 0.2, {backgroundColor:"#004", color:"orange"}, "-=0.1")
element.animation = tl;
})
// This part works if i don't use imageOver and imageOut
// $("li").hover(over, out);
// function over(){
// this.animation.play();
// }
// function out(){
// this.animation.reverse();
// }
},
imageOver: function (e) {
// What goes here?
},
imageOut: function (e) {
// What goes here?
}
});
使用事件哈希,您可以通过
事件
对象访问事件目标,并且仍然可以通过此
访问视图实例
imageOver: function (event) {
$(event.target).animation.play();
},
imageOver: function (event) {
var target = event.currentTarget;
// What goes here?
target.animation.play();
},
imageOut: function (event) {
var target = event.currentTarget;
// What goes here?
target.animation.reverse();
}