Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added movestart and movestop events. #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ <h2>Initialize options</h2>
<li><strong>trackSize: false</strong> -- Set the size of the scrollbar to auto(false) or a fixed number.</li>
<li><strong>thumbSize: false</strong> -- Set the size of the thumb to auto(false) or a fixed number.</li>
<li><strong>scrollInvert: false</strong> -- Inverts the direction of scrolling.</li>
<li><strong>moveStopThreshold: 300</strong> -- Number of milliseconds without any 'move' event to trigger the 'movestop' event.</li>
</ul>

<h2>Properties</h2>
Expand Down Expand Up @@ -496,6 +497,8 @@ <h2>Events</h2>

<ul class="list">
<li><strong>move</strong> -- The move event will trigger on every drag or scroll.</li>
<li><strong>movestart</strong> -- The move event will trigger on every drag or scroll start.</li>
<li><strong>movestop</strong> -- The move event will trigger on every drag or scroll end.</li>
</ul>
</section>
</article>
Expand Down
34 changes: 34 additions & 0 deletions lib/jquery.tinyscrollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
, scrollInvert : false // Enable invert style scrolling
, trackSize : false // Set the size of the scrollbar to auto or a fixed number.
, thumbSize : false // Set the size of the thumb to auto or a fixed number
, moveStopThreshold : 300 // Set the number of milliseconds since last move event to trigger moveStop
}
;

Expand Down Expand Up @@ -170,6 +171,37 @@
}
}

var updateMoveStop = (function moveStopHandler ()
{
var moving = false,
lastWheelEvent;

function timer()
{
setTimeout(function () {
if(lastWheelEvent + self.options.moveStopThreshold > new Date().getTime()){
timer();
} else {
$container.trigger("movestop");
moving = false;
}
}, self.options.moveStopThreshold);

}

function move ()
{
lastWheelEvent = new Date().getTime();
if(!moving) {
$container.trigger("movestart");
moving = true;
timer();
}
}

return move;
})();

function wheel(event)
{
if(self.contentRatio < 1)
Expand All @@ -183,6 +215,7 @@
self.contentPosition = Math.min((self.contentSize - self.viewportSize), Math.max(0, self.contentPosition));

$container.trigger("move");
updateMoveStop();

$thumb.css(posiLabel, self.contentPosition / self.trackRatio);
$overview.css(posiLabel, -self.contentPosition);
Expand Down Expand Up @@ -212,6 +245,7 @@
self.contentPosition = thumbPositionNew * self.trackRatio;

$container.trigger("move");
updateMoveStop();

$thumb.css(posiLabel, thumbPositionNew);
$overview.css(posiLabel, -self.contentPosition);
Expand Down
4 changes: 2 additions & 2 deletions lib/jquery.tinyscrollbar.min.js

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

34 changes: 34 additions & 0 deletions lib/tinyscrollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
, scrollInvert : false // Enable invert style scrolling
, trackSize : false // Set the size of the scrollbar to auto or a fixed number.
, thumbSize : false // Set the size of the thumb to auto or a fixed number.
, moveStopThreshold : 300 // Set the number of milliseconds since last move event to trigger moveStop
}
;

Expand Down Expand Up @@ -170,6 +171,37 @@
}
}

var updateMoveStop = (function moveStopHandler ()
{
var moving = false,
lastWheelEvent;

function timer()
{
setTimeout(function () {
if(lastWheelEvent + self.options.moveStopThreshold > new Date().getTime()){
timer();
} else {
$container.trigger("movestop");
moving = false;
}
}, self.options.moveStopThreshold);

}

function move ()
{
lastWheelEvent = new Date().getTime();
if(!moving) {
$container.trigger("movestart");
moving = true;
timer();
}
}

return move;
})();

function wheel(event)
{
if(self.contentRatio < 1)
Expand All @@ -183,6 +215,7 @@
self.contentPosition = Math.min((self.contentSize - self.viewportSize), Math.max(0, self.contentPosition));

$container.dispatchEvent(moveEvent);
updateMoveStop();

$thumb.style[posiLabel] = self.contentPosition / self.trackRatio + "px";
$overview.style[posiLabel] = -self.contentPosition + "px";
Expand Down Expand Up @@ -211,6 +244,7 @@
self.contentPosition = thumbPositionNew * self.trackRatio;

$container.dispatchEvent(moveEvent);
updateMoveStop();

$thumb.style[posiLabel] = thumbPositionNew + "px";
$overview.style[posiLabel] = -self.contentPosition + "px";
Expand Down
Loading