I want to scroll the content of a div with the mousewheel jquery plugin. I have this but its not working. Any thoughts?
$(function() {
$('#contentBox').bind('mousewheel', function(event, delta) {
if (delta > 0) {
$('#contentBox').css('top', parseInt($('#contentBox').css('top'))+40);
} else {
$('#contentBox').css('top', parseInt($('#contentBox').css('top'))-40);
}
return false;
});
});
Just a guess : does adding + ‘px’ to the CSS value fix things? Actually, what does ‘media’ refer to?
UPDATE
OK, I’ve had a chance to test your code and it all looks good, presuming you’ve set the CSS up properly. Have you actually assigned a value for
topon #contentBox already? Without an existing value,parseInt($('#contentBox').css('top'))will returnNaN. Here’s the code that I used:Note that I’ve used the ternary operator to simplify/reduce the code a bit, but this is just to keep the size of this answer down a bit, and is entirely optional. I’ve also just used some test CSS there to see what I’m doing; I’m sure yours is different!