Skip to content

Instantly share code, notes, and snippets.

@Kirkman
Last active August 29, 2015 14:13
Show Gist options
  • Save Kirkman/87532d5e3bc5cd8ed844 to your computer and use it in GitHub Desktop.
Save Kirkman/87532d5e3bc5cd8ed844 to your computer and use it in GitHub Desktop.
Circular scrolling for Synchronet's frame.js
this.scrollCircular = function(x,y) {
var update = false;
if (typeof y == "number" && y > 0 && settings.v_scroll) {
for (var i=0; i<y; i++) {
var rowToMove = properties.data.shift();
properties.data.push(rowToMove);
update = true;
}
}
else if (typeof y == "number" && y < 0 && settings.v_scroll) {
for (var i=0; i<Math.abs(y); i++) {
var rowToMove = properties.data.pop();
properties.data.unshift(rowToMove);
update = true;
}
}
else if (typeof x == "number" && x > 0 && settings.h_scroll) {
for (var i=0; i<x; i++) {
for ( yl = 0; yl < properties.data.length; yl++) {
var cellToMove = properties.data[yl].shift();
properties.data[yl].push(cellToMove);
}
update = true;
}
}
else if (typeof x == "number" && x < 0 && settings.h_scroll) {
for (var i=0; i<Math.abs(x); i++) {
for ( yl = 0; yl < properties.data.length; yl++) {
var cellToMove = properties.data[yl].pop();
properties.data[yl].unshift(cellToMove);
}
update = true;
}
}
if (update) {
this.refresh();
}
return update;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment