I have a div (transcript_container) which contains the subtitles to an audio playing. Each subtitle is in synch with the audio.
The height of the div is 200px. When the list of subtitles is longer than 200px, the text automatically scrolls up so that the highlighted subtitle gets on top and is always visible in the div container. This works perfectly in all browsers except for Firefox.
This is the HTML:
<div style="display:table; margin-left:auto; margin-right:auto;">
<div style="display:table-row;">
<div class="transcript_container" id="transcript_container">
<div style="height:200px; overflow:-moz-scrollbars-vertical;"> (I had to add this div with the overflow for firefox otherwise the text wouldn't be contained in the div in firefox)
Subtitles......
...............
</div>
</div>
</div>
</div>
This is the CSS:
.transcript_container{
display:table-cell;
width: 500px;
height:200px;
border: 1px solid #999;
-webkit-border-radius: 5px 5px 5px 5px;
-moz-border-radius: 5px 5px 5px 5px;
border-radius: 5px 5px 5px 5px;
text-align:left;
color:#036;
margin-left:auto;
margin-right:auto;
overflow:scroll;
}
This is the jQuery script:
jQuery('.subtitle_highlight').each(function(){
if (jQuery(this).offset().top - jQuery('#transcript_container').offset().top > 200){
jQuery('#transcript_container').animate({scrollTop: jQuery('#transcript_container').scrollTop() + 200 + 'px'}, 300);
}
});
Example:
----------------------------------------DIV: Transcript_Container------
subtitle 1
subtitle 2
subtitle 3
----------------------------------------------End of DIV---------------
subtitle 4 (hidden area)
subtitle 5
subtitle 6
When subtitle 3 is highlighted, subtitle 4 scrolls up to the top of the DIV and becomes visible. The synchronization continues with subtitles 4, 5 and 6. In firefox, subtitle 4 doesn't go to the top of the div when it's highlighted, but remains hidden.
How can I make it compatible for firefox as well ? Is there an alternative to ScrollTop that could work with all browsers ?