0

そのため、ページ上の各 .featured-image が使用する再利用可能な関数を作成しようとしています。バックボーンイベントを使用せず、コメントアウトされたコードを書くだけで機能します。コメント付きのコードを模倣するイベント 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?
        }

    });
4

2 に答える 2

1

イベント ハッシュを使用すると、オブジェクトを介してイベント ターゲットにeventアクセスし、引き続きビュー インスタンスにアクセスできます。this

  imageOver: function (event) {
      $(event.target).animation.play();
  },
于 2013-02-08T17:07:40.567 に答える
1
    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();
    }
于 2013-02-08T21:01:01.000 に答える