Skip to content

Commit

Permalink
Merge pull request #18 from xahgmah/master
Browse files Browse the repository at this point in the history
Feature/scroll to center (#1)
  • Loading branch information
walsh9 authored Mar 27, 2017
2 parents 2049a1a + d0002ef commit 76f96a0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ object may contain any of the following properties:

Set to false to disable autoscrolling.

#### scrollToCenter
**Default:** false

By default current row shows on the bottom on autoscrolling. Set to true to show it in the center

#### clickArea
**Default:** 'line'

Expand Down
13 changes: 9 additions & 4 deletions dist/videojs-transcript.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ var defaults = {
showTitle: true,
showTrackSelector: true,
followPlayerTrack: true,
scrollToCenter: false,
stopScrollWhenInUse: true,
};

Expand Down Expand Up @@ -246,17 +247,21 @@ var scrollerProto = function(plugin) {
var elementOffsetBottom = element.offsetTop + element.clientHeight;
var relTop = element.offsetTop - parent.offsetTop;
var relBottom = (element.offsetTop + element.clientHeight) - parent.offsetTop;
var centerPosCorrection = 0;
var newPos;

if (plugin.settings.scrollToCenter){
centerPosCorrection = Math.round(parent.clientHeight/2 - element.clientHeight/2);
}
// If the top of the line is above the top of the parent view, were scrolling up,
// so we want to move the top of the element downwards to match the top of the parent.
if (relTop < parent.scrollTop) {
newPos = element.offsetTop - parent.offsetTop;
if (relTop < parent.scrollTop + centerPosCorrection) {
newPos = element.offsetTop - parent.offsetTop -centerPosCorrection;

// If the bottom of the line is below the parent view, we're scrolling down, so we want the
// bottom edge of the line to move up to meet the bottom edge of the parent.
} else if (relBottom > (parent.scrollTop + parent.clientHeight)) {
newPos = elementOffsetBottom - parentOffsetBottom;
} else if (relBottom > (parent.scrollTop + parent.clientHeight) - centerPosCorrection) {
newPos = elementOffsetBottom - parentOffsetBottom + centerPosCorrection;
}

// Don't try to scroll if we haven't set a new position. If we didn't
Expand Down
2 changes: 1 addition & 1 deletion dist/videojs-transcript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 76f96a0

Please sign in to comment.