Skip to content

Instantly share code, notes, and snippets.

@jedmund
Created May 2, 2011 08:12
Show Gist options
  • Save jedmund/951295 to your computer and use it in GitHub Desktop.
Save jedmund/951295 to your computer and use it in GitHub Desktop.
function moveLeft() {
var left = $('.slideshow .inner').css('left');
left = parseInt(left);
if ($('.slideshow .inner').css('left') < 0) {
$('.slideshow .inner').animate({left: '+=10'}, 100);
}
console.log("Firing left");
}
function moveRight() {
$('.slideshow .inner').css('left', '-=10');
console.log("Firing right");
}
$('document').ready(function() {
var hoverInterval;
var slideshowWidth;
console.log("Ready!!");
$('.slideshow').mousemove(function(e) {
// Get the width of the slideshow
slideshowWidth = $(this).width();
console.log("slideshow width: " + slideshowWidth);
// Get the position of X and Y relative to this element
var mouseX = e.pageX - this.offsetLeft;
var mouseY = e.pageY - this.offsetTop;
console.log(mouseX + ", " + mouseY);
// Bounds detection
if (mouseX < 150) {
console.log("In bounds on left edge");
hoverInterval = setInterval(moveLeft, 100);
} else if (mouseX > (slideshowWidth-150)) {
console.log("In bounds on right edge");
hoverInterval = setInterval(moveRight, 100);
}
});
$('.slideshow').mouseout(function(e) {
console.log("Mouseout!");
clearInterval(hoverInterval);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment