i tried to add a smoothScroll animation on each button that has a .smoothScroll class.
so i did this:
// SmoothSCroll
var smoothScroll = document.querySelectorAll('.smoothScroll');
[].forEach.call(smoothScroll, function (el) {
el.addEventListener('click', function() {
var offset = $(this.hash).offset().top;
$('html, body').stop().animate({
scrollTop: offset - (window.innerHeight/2) + ($(this.hash).innerHeight()/2)
}, 400 );
return false;
});
});
https://jsfiddle.net/jt2jo3pt/2/
I don't know if you noticed what happened, but there is a little flash when the click triggered ( the scrollbar goes down a little before smoothscrolling )
But when i tried with full Jquery like this:
$('.smoothScroll').click(function(e){
var offset = $(this.hash).offset().top;
$('html, body').stop().animate({
scrollTop: offset - (window.innerHeight/2) + ($(this.hash).innerHeight()/2)
}, 400 );
return false;
});
I don't have this bubbling effect: https://jsfiddle.net/34w72v1v/
Do you have any idea what could cause this issue with querySelectorAll method?
I try to not use jQuery so i need to know what's happening to learn :)
Thanks for your time.