2016-12-04 98 views
0

我想用jQuery waypoint淡入淡出所有滾動元素。當我滾動到圖像時,我添加了某個類來淡入其中。爲此我使用jQuery Waypoint。當我滾動到圖像console.log顯示「滾動到圖像」,但它不能添加類「這個」的圖像。使用jQuery Waypoint淡化所有元素

$(document).ready(function() { 
    $('img').waypoint(function() { 
      console.log("Scrolled to Image"); 
      $(this).addClass("Test"); 
    }, 
    { 
     offset: '50%', 
     triggerOnce: true 
    });  
}); 

回答

1

this在回調中指路點對象。改爲嘗試this.element(請參閱http://imakewebthings.com/waypoints/guides/getting-started/ - 關於此確切問題,請參見特殊部分)

$(document).ready(function() { 
    $('img').waypoint(function() { 
      console.log("Scrolled to Image"); 
      $(this.element).addClass("Test"); 
    }, 
    { 
     offset: '50%', 
     triggerOnce: true 
    });  
}); 
相關問題