I'm developping a website to learn a bit more about javascript, css and html. A draft of this website is here : http://test13111983.free.fr/
I'm having some trouble with the scrolling : scrooling up and down triggers an horizontal scroll.
When I'm scrolling down and up with the trackpad on my laptop the animation is quite smooth on Chrome, but horrible on Firefox.
Besides on Chrome the left part of the page tend to disappear momentaneously when I'm scrolling back up.
Here's the js code I use for the scrolling :
var scroll = 0;
var target_page = "";
var round = 0;
var speed=50;
var timeout = null;
var diff = 0;
$('.accueil').on('mousewheel DOMMouseScroll', function(e){
if(typeof e.originalEvent.detail == 'number' && e.originalEvent.detail !== 0) {
if(e.originalEvent.detail > 0) {
scroll++;
} else if(e.originalEvent.detail < 0){
scroll--;
}
} else if (typeof e.originalEvent.wheelDelta == 'number') {
if(e.originalEvent.wheelDelta < 0) {
scroll++;
} else if(e.originalEvent.wheelDelta > 0) {
scroll--;
}
}
if(scroll>0){
round = Math.trunc(scroll/speed);
target_page = '.page:eq('+(numItems-round-2)+')';
$('.accueil').css("width", (0.32+0.2*(numItems))*$(window).innerWidth()+0.3*$(window).innerWidth()*scroll/speed);
$('.accueil').css("left", -0.5*$(window).innerWidth()*scroll/speed);
$(target_page).css("width", 0.2*$(window).innerWidth()*(1+1.5*(scroll/speed-round)));
$(target_page+' .photo').css("height", -0.01*$(window).innerHeight()+0.2*$(window).innerHeight()*(1+1.5*(scroll/speed-round)));
$(target_page+' .photo').css("width", -0.01*$(window).innerWidth()+0.2*$(window).innerWidth()*(1+1.5*(scroll/speed-round)));
if(scroll/speed- round > 0.5){$(target_page+' .numero').css("color", "#000");}else{$(target_page+' .numero').css("color", "#eaeaea");}
$(target_page+' .titre, '+target_page+' .date, '+target_page+' .categorie, '+target_page+' .sous_titre, '+target_page+' .numero').css("margin-left", 0.2*$(window).innerWidth()*(0.05+1.5*(scroll/speed-round)));
clearTimeout(timeout);
timeout = setTimeout(function() {
if(scroll/speed- round <= 0.5){scroll=round*speed;$(target_page+' .numero').css("color", "#eaeaea");}
else{scroll=(round+1)*speed;$(target_page+' .numero').css("color", "#000");};
$('.accueil').css("width", (0.32+0.2*(numItems))*$(window).innerWidth()+0.3*$(window).innerWidth()*scroll/speed);
$('.accueil').css("left", -0.5*$(window).innerWidth()*scroll/speed);
$(target_page).css("width", 0.2*$(window).innerWidth()*(1+1.5*(scroll/speed-round)));
$(target_page+' .photo').css("height", -0.01*$(window).innerHeight()+0.2*$(window).innerHeight()*(1+1.5*(scroll/speed-round)));
$(target_page+' .photo').css("width", -0.01*$(window).innerWidth()+0.2*$(window).innerWidth()*(1+1.5*(scroll/speed-round)));
$(target_page+' .titre, '+target_page+' .date, '+target_page+' .categorie, '+target_page+' .sous_titre, '+target_page+' .numero').css("margin-left", 0.2*$(window).innerWidth()*(0.025+1.5*(scroll/speed-round)));
}, 1000);
}
else{scroll=0;}
});
What the code does on scroll is 1) widdening a div 2) and the page 3) and move it horizontally
I would like a cross-browser smooth and efficient transition. Any advice ?
Thanking you in advance.