Skip to content

Commit

Permalink
Kind of a fix for Issues #372 and #125. Now Sticktobottom sticks to b…
Browse files Browse the repository at this point in the history
…ottom and you have to turn off maintainposition if you like to use it
  • Loading branch information
illuusio committed Jun 25, 2020
1 parent 295421f commit 6143288
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
13 changes: 10 additions & 3 deletions examples/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,24 @@ <h2 id="stickToBottom">stickToBottom<span class="setting-type">- boolean (defaul
<p>
If <a href="#maintainPosition">maintainPosition</a> is true and the scrollpane is scrolled to the
bottom then the scrollpane then the scrollpane will remain scrolled to the bottom even if new content
is added to the pane which makes it taller.
is added to the pane which makes it taller. User has to do this scroll manually.
If maintainPosition is false and stickToBottom is true it will always jump to bottom when reinitialize
happened and stay there. Notice then it does not maintain position only sticks to bottom even User
scrolls pane up.
</p>
<h2 id="stickToRight">stickToRight<span class="setting-type">- boolean (default false)</span></h2>
<p>
If <a href="#maintainPosition">maintainPosition</a> is true and the scrollpane is scrolled to its
right edge then the scrollpane then the scrollpane will remain scrolled to the right edge even if new
content is added to the pane which makes it wider.
content is added to the pane which makes it wider. User has to do this scroll manually as it tries
to keep position.
If maintainPosition is false and stickToRight is true it will always jump to right when new content
appears and stay there. Notice then it does not maintain position only sticks to right even User
scrolls pane left.
</p>
<h2 id="resizeSensor">resizeSensor <span class="setting-type">- boolean (default false)</span></h2>
<p>
Whether jScrollPane should automatically reinitialise itself whenever the content inside changes in size.
Whether jScrollPane should automatically reinitialise itself whenever the content inside changes in size.
This can help with instances when the size of the content of the scrollpane (or the
surrounding element) changes. This is more performant than using autoReinitialise, however autoReinitialise
should be used if elements inside the scrollpane are absolutely positioned. <a href="resize_sensor.html">Demo</a>.
Expand Down
21 changes: 18 additions & 3 deletions script/jquery.jscrollpane.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@
newPaneWidth, newPaneHeight, maintainAtBottom = false, maintainAtRight = false;

settings = s;
lastContentX = 0;
lastContentY = 0;

if (pane === undefined) {
originalScrollTop = elem.scrollTop();
Expand Down Expand Up @@ -241,6 +243,7 @@
elem.addClass('jspScrollable');

isMaintainingPositon = settings.maintainPosition && (verticalDragPosition || horizontalDragPosition);

if (isMaintainingPositon) {
lastContentX = contentPositionX();
lastContentY = contentPositionY();
Expand All @@ -250,7 +253,7 @@
initialiseHorizontalScroll();
resizeScrollbars();

if (isMaintainingPositon) {
if (settings.stickToBottom || settings.stickToRight) {
scrollToX(maintainAtRight ? (contentWidth - paneWidth ) : lastContentX, false);
scrollToY(maintainAtBottom ? (contentHeight - paneHeight) : lastContentY, false);
}
Expand Down Expand Up @@ -1059,13 +1062,25 @@
function isCloseToBottom()
{
var scrollableHeight = contentHeight - paneHeight;
return (scrollableHeight >= 20) && (scrollableHeight - contentPositionY() < 10);

if(settings.maintainPosition == true)
{
return (scrollableHeight >= 20) && (scrollableHeight - contentPositionY() < 10);
}

return true;
}

function isCloseToRight()
{
var scrollableWidth = contentWidth - paneWidth;
return (scrollableWidth >= 20) && (scrollableWidth - contentPositionX() < 10);

if(settings.maintainPosition == true)
{
return (scrollableWidth >= 20) && (scrollableWidth - contentPositionX() < 10);
}

return true;
}

function initMousewheel()
Expand Down

0 comments on commit 6143288

Please sign in to comment.