gpt4 book ai didi

javascript - 如何将鼠标的 currentTarget 传递到时间线最大函数中

转载 作者:行者123 更新时间:2023-12-02 19:01:09 25 4
gpt4 key购买 nike

因此,我尝试创建一个可重用的函数,供我页面上的每个 .featured-image 使用。如果我不使用 Backbone 事件:并且我只编写注释掉的代码,它就可以工作。我如何获得事件 imageOver 和 imageOut 模仿注释代码?

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?
}

});

最佳答案

使用事件哈希,您可以通过 event 对象访问事件目标,并仍然通过 this 访问 View 实例

  imageOver: function (event) {
$(event.target).animation.play();
},

关于javascript - 如何将鼠标的 currentTarget 传递到时间线最大函数中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14777433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com