I have a an element .scroll with overflow:hidden whose content is larger than itself. I'm using javascript to scroll the content up and down by hovering to links - .scrollcontrol.up and .scrollcontrol.down, placed on top and bottom of the .scroll element respectively.
Following is the code I've so far:
$(function() {
var ele = $('#scroll');
var speed = 25, scroll = 5, scrolling;
$('.scrollcontrol.up').mouseenter(function() {
// Scroll the element up
scrolling = window.setInterval(function() {
ele.scrollTop( ele.scrollTop() - scroll );
}, speed);
});
$('.scrollcontrol.down').mouseenter(function() {
// Scroll the element down
scrolling = window.setInterval(function() {
ele.scrollTop( ele.scrollTop() + scroll );
}, speed);
});
$('.scrollcontrol.up, .scrollcontrol.down').bind({
click: function(e) {
// Prevent the default click action
e.preventDefault();
},
mouseleave: function() {
if (scrolling) {
window.clearInterval(scrolling);
scrolling = false;
}
}
});
});
and I would like that when I hover on .scrollcontrol.down, .scrollcontrol.up fades in and when the scrolling ends .scrollcontrol.down fades out, and vice versa.
You can find the full code in this JSFiddle
Looking forward for your solutions!