4
I’m trying to implement an infinite scroll on my site, like this one, but I’m having trouble making the script that picks up the mouse scrolling event. I tried using this script (below) that I picked up on a website, but it’s not exactly what I need. Does anyone have any suggestions?
cont=0
function handle(delta) {
var nav = document.getElementById('navegacao');
var ln = nav.getElementsByTagName('a');
if (delta < 0){
cont=cont+1;
ln[cont].click();
}
else{
cont=cont-1;
ln[cont].click();
}
}
function wheel(event){
var delta = 0;
if (!event) event = window.event;
if (event.wheelDelta) {
delta = event.wheelDelta/120;
} else if (event.detail) {
delta = -event.detail/3;
}
if (delta)
handle(delta);
if (event.preventDefault)
event.preventDefault();
event.returnValue = false;
}
/* Initialization code. */
if (window.addEventListener)
window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;
What does this code do that you don’t like? What exactly do you need to do?
– bfavaretto
So @bfavaretto I need that when I scroll the mouse move to the next element of my page like this: http://wandaprint.com/home. but this code (which I posted and was the only one I found), jumps two in two Oo elements
– Odair
That site there does not pass in Pagespeed: his preloader is close to 20% here already almost a minute ago.
– Gustavo Rodrigues
hahahaha @Gustavorodrigues It really is a very heavy site, it has many images but it is a well done site (the design part at least rs)
– Odair
I still hope that the Pagespeed popularize, even more here in Brazil where the speeds are not so high. I hope he finishes charging so I can comment on him.
– Gustavo Rodrigues
Page uploaded! This page doesn’t need a preloader for the images so much. Organize the elements first then load the images as the user navigates through the images.
– Gustavo Rodrigues