Skip to content

Instantly share code, notes, and snippets.

@justinhillsjohnson
Created May 21, 2013 21:00
Show Gist options
  • Save justinhillsjohnson/5623209 to your computer and use it in GitHub Desktop.
Save justinhillsjohnson/5623209 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
$(document).mousemove(function(e) {
var mouseX = e.pageX;
var $bottle = $('#bottle-spin');
var $status = $('#status');
var match = false;
var width = $bottle.width();
var i = 0;
var ranges = {
'range1': {
'min': 30,
'max': 60
},
'range2': {
'min': 60,
'max': 90
},
'range3': {
'min': 90,
'max': 120
},
'range4': {
'min': 120,
'max': 150
},
'range5': {
'min': 150,
'max': 180
}
}
$status.html(mouseX);
for (var range in ranges) {
i++;
if (mouseX >= ranges[range].min && mouseX < ranges[range].max) {
$bottle.css('background-position', width * i + 'px ' + ' 0');
match = true;
break;
}
}
if (match == false) {
$bottle.css('background-position', '0, 0')
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment