I have page where i have to play certain audio files which are related to the text and when related audio file is played then related text should be highlight. Issue i am facing is that i need to keep the highlighted div visible to the reason. I am not sure how i can automatically scroll down the page to keep the highlighted div visible so that he can read it.
HTML
<audio id="myAudio">
<source src="" type="audio/mpeg">
</audio>
<button>Play Audio</button>
<div class="wrapper">
<span>Rooster</span>
<span>Cat</span>
<span>Horse</span>
<span>Elephant</span>
<span>Vulture</span>
<span>Duck</span>
<span>Rooster</span>
<span>Cat</span>
<span>Horse</span>
<span>Elephant</span>
<span>Vulture</span>
<span>Duck</span>
<span>Rooster</span>
<span>Cat</span>
<span>Horse</span>
<span>Elephant</span>
<span>Vulture</span>
<span>Duck</span>
<span>Rooster</span>
<span>Cat</span>
<span>Horse</span>
<span>Elephant</span>
<span>Vulture</span>
<span>Duck</span>
</div>
I tried following code but this not working
$aud.onplay = function() {
$btn.text("Pause Audio");
playing = true;
$("div > span:nth-child(" + (audioIndex + 1) + ")").addClass("playing");
var wHeight = $( window ).height();
var wHalfHeight = wHeight;
var x = $(".playing").position();
var curentSpanPosition = x.top();
wHalfHeight = wHalfHeight/2;
//if ( curentSpanPosition > wHalfHeight )
//{
$(".playing").animate({
scrollTop: curentSpanPosition
});
//}
};