Hi Stackoverflow fellows,
I want to create a website with one page scrolling but i don't want to use any external library. So i came-up with this technique, It works perfectly fine for a local test but i want to know if this piece of code is logical or this may have potential issues in a full website. I am asking because in my search i did not find this approach for a one page site, i want to know the reason why not this. So please point me in right direction. Any suggestions or comments are welcome. Thanks for your support. https://jsfiddle.net/emalik/xpvt214o/539446/
var current
$(function() {
var timerId;
$('.one-page').bind('DOMMouseScroll mousewheel', function(e){
e.preventDefault();
var $current = $('section.current');
if(e.originalEvent.wheelDelta > 0 || e.originalEvent.detail < 0) {
//console.log(e.originalEvent.wheelDelta);
//console.log("UP");
$prev = $current.prev();
if ($prev.length) {
clearTimeout(timerId);
timerId = setTimeout(function(){
$current.removeClass('current');
$prev.addClass('current');
$('body,html').animate({
scrollTop: $('.current').offset().top
}, 200);
}, 200)
}
}
else{
// console.log("DOWN");
$next = $current.next();
if ($next.length) {
clearTimeout(timerId);
timerId = setTimeout(function(){
$current.removeClass('current');
$next.addClass('current');
$('body,html').animate({
scrollTop: $('.current').offset().top
}, 200);
, 200)
}
}
});
});