I am using the following script to with the audio controls class="box follow-scroll" to make it float while the page is scrolling. But I was wondering if it possible to make it float only while the audio is in either play or pause mode? If it stopped it didn't start, it stays where it is.
$(window).load(function(){
(function($) {
var element = $('.follow-scroll'),
originalY = element.offset().top;
var topMargin = 20;
element.css('position', 'relative');
$(window).on('scroll', function(event) {
var scrollTop = $(window).scrollTop();
element.stop(false, false).animate({
top: scrollTop < originalY ? 0 : scrollTop - originalY + topMargin
}, 300);
});
})(jQuery);
});
The html:
<audio controls class="box follow-scroll">
<source src="http://techslides.com/demos/samples/sample.ogg" type="audio/ogg">
<source src="http://techslides.com/demos/samples/sample.mp3" type="audio/mpeg">
</audio>