Audio on scroll

后端 未结 1 1927
一整个雨季
一整个雨季 2021-01-01 04:22

I\'m doing a website with the skrollr plugin and I\'m almost done with the pictures and scrolling itself, so I\'m trying to add the audio now, but I can\'t seem to make the

相关标签:
1条回答
  • 2021-01-01 04:29
    var playing = false;
    var audioElm = $('#soundTour').get(0);
    $(window).scroll(function() {
      var pageScroll = $(window).scrollTop();
      if(!playing && pageScroll > 500 && pageScroll < 3000){
        audioElm.play();
        playing = true;
      }else if(pageScroll > 3000 || pageScroll < 500){
        audioElm.pause();
        playing = false;
      }
    });
    

    You need to add some conditions. (I define the variables outside for performance matters, as jQuery scroll has really bad performance, that gets even worse on phones).

    Pen: http://codepen.io/vandervals/pen/KpWzVJ

    0 讨论(0)
提交回复
热议问题