jQuery(document).ready(function($){
var $window = $(window);
var $elem = $(".animated")
function isScrolledIntoView($elem, $window) {
var docViewTop = $window.scrollTop();
var docViewBottom = docViewTop + $window.height();
var elemTop = $elem.offset().top;
var elemBottom = elemTop + $elem.height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
$(document).on("scroll", function () {
if (isScrolledIntoView($elem, $window)) {
$("#graph1").attr("src","images/graphsSECHE_500x500_noloop2.gif");
}
});
});
答案 0 :(得分:0)
在页面加载时初始化一个布尔值,例如:
var played = false;
然后检查你的动画是否已经播放过,并且不要忘记在if by中实际设置为true:
if (isScrolledIntoView($elem, $window) && played === false) {
$("#graph1").attr("src","images/graphsSECHE_500x500_noloop2.gif");
played = true;
}