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

Option to scroll by total pixels scrolled or proportionally #69

Merged
merged 6 commits into from Feb 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 17 additions & 4 deletions lib/client/browser-sync-client.js
Expand Up @@ -160,6 +160,7 @@

if (data.assetFileName && data.fileExtension) {


var domData = this.getElems(data.fileExtension);
var elems = this.getMatches(domData.elems, data.assetFileName, domData.attr);

Expand Down Expand Up @@ -550,9 +551,12 @@
listeners: {
scroll: function () {

var url;
var pos, url;

var scrollTop = ghost.getScrollTopPercentage(); // Get % of y axis of scroll
var scrollTop = {
raw: ghost.getScrollTop(), // Get px of y axis of scroll
proportional: ghost.getScrollTopPercentage() // Get % of y axis of scroll
};
var newScroll = new Date().getTime();
var scrollThrottle = 0;

Expand All @@ -571,6 +575,11 @@
if (scope.ghostMode.enabled) {
scope.ghostMode.lastScroll = newScroll;

if (scope.options.scrollProportionally) {
pos = scrollTop.proportional;
} else {
pos = scrollTop.raw;
}
url = window.location.host + window.location.pathname;

ghost.emitEvent("scroll", {
Expand Down Expand Up @@ -692,9 +701,13 @@

socket.on("scroll:update", function (data) {
if (data.url === window.location.host + window.location.pathname) {
var scrollSpace = ghost.getScrollSpace();
scope.ghostMode.enabled = false;
window.scrollTo(0, scrollSpace[1] * data.position); // proportional scroll
if (scope.options.scrollProportionally) {
var scrollSpace = ghost.getScrollSpace();
window.scrollTo(0, scrollSpace[1] * data.position.proportional); // % of y axis of scroll to px
} else {
window.scrollTo(0, data.position.raw);
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion lib/client/browser-sync-client.min.js

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

8 changes: 8 additions & 0 deletions lib/config.js
Expand Up @@ -89,6 +89,14 @@ module.exports = {
*/
injectChanges: true,

/*
|--------------------------------------------------------------------------
| Scroll Proportionally (true|false)
|--------------------------------------------------------------------------
| https://github.com/shakyShane/browser-sync/wiki/options#wiki-scrollproportionally
*/
scrollProportionally: true,

/*
|--------------------------------------------------------------------------
| Scroll Throttle (milliseconds)
Expand Down
3 changes: 2 additions & 1 deletion lib/index.js
Expand Up @@ -26,6 +26,7 @@ var defaultConfig = {
notify: true,
devMode: false,
fileTimeout: 1000,
scrollProportionally: true,
scrollThrottle: 0,
reloadDelay: 0,
injectChanges: true,
Expand Down Expand Up @@ -455,4 +456,4 @@ module.exports.init = function (files, userConfig) {
}
}
return setup.kickoff(files, config);
};
};