我想在滾動到定義的ID #counter時播放聲音。它工作正常,但我想玩一次。當有人再次上下滾動時,音樂就處於一種循環中。如何阻止?一次滾動觸發播放功能
// play countdown sound on scroll when you hit #counter
$(window).scroll(function() {
var elemTop = $('#counter').offset().top,
elemHeight = $('#counter').outerHeight(),
windowHeight = $(window).height(),
windowScroll = $(this).scrollTop();
var countdownSound = new Audio('./music/countdown.mp3');
if(windowScroll > (elemTop + elemHeight - windowHeight)) {
countdownSound.play();
}
});
也許:'$(window).off('scroll')' –