Skip to content

Commit

Permalink
Merge pull request #60 from mikejacobson/scroll-active-to-center
Browse files Browse the repository at this point in the history
Scroll active tab to center rather than minimally within view
  • Loading branch information
mikejacobson authored Oct 14, 2018
2 parents 2f1e6f7 + 5bc322d commit 983c0fc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-bootstrap-scrolling-tabs",
"version": "2.4.0",
"version": "2.5.0",
"main": [
"./dist/jquery.scrolling-tabs.js",
"./dist/jquery.scrolling-tabs.css"
Expand Down
16 changes: 12 additions & 4 deletions dist/jquery.scrolling-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,9 @@
activeTabLeftPos,
activeTabRightPos,
rightArrowLeftPos,
activeTabWidth,
leftPosOffset,
offsetToMiddle,
leftScrollArrowWidth,
rightScrollArrowWidth;

Expand All @@ -955,13 +958,14 @@
}

rightScrollArrowWidth = stc.$slideRightArrow.outerWidth();
activeTabWidth = $activeTab.outerWidth();

/**
* @author poletaew
* We need relative offset (depends on $fixedContainer), don't absolute
*/
activeTabLeftPos = $activeTab.offset().left - stc.$fixedContainer.offset().left;
activeTabRightPos = activeTabLeftPos + $activeTab.outerWidth();
activeTabRightPos = activeTabLeftPos + activeTabWidth;

rightArrowLeftPos = stc.fixedContainerWidth - rightScrollArrowWidth;

Expand All @@ -981,13 +985,17 @@
}
} else {
if (activeTabRightPos > rightArrowLeftPos) { // active tab off right side
stc.movableContainerLeftPos -= (activeTabRightPos - rightArrowLeftPos + rightScrollArrowWidth);
leftPosOffset = activeTabRightPos - rightArrowLeftPos + rightScrollArrowWidth;
offsetToMiddle = stc.fixedContainerWidth / 2;
leftPosOffset += offsetToMiddle - (activeTabWidth / 2);
stc.movableContainerLeftPos -= leftPosOffset;
smv.slideMovableContainerToLeftPos();
return true;
} else {
leftScrollArrowWidth = stc.$slideLeftArrow.outerWidth();
if (activeTabLeftPos < leftScrollArrowWidth) { // active tab off left side
stc.movableContainerLeftPos += leftScrollArrowWidth - activeTabLeftPos;
if (activeTabLeftPos < 0) { // active tab off left side
offsetToMiddle = stc.fixedContainerWidth / 2;
stc.movableContainerLeftPos += (-activeTabLeftPos) + offsetToMiddle - (activeTabWidth / 2);
smv.slideMovableContainerToLeftPos();
return true;
}
Expand Down
Loading

0 comments on commit 983c0fc

Please sign in to comment.