1

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) 
            }
        }
    });
});
dee.ronin
  • 1,040
  • 12
  • 22
e-malik
  • 23
  • 7
  • I believe this question must be asked @ https://codereview.stackexchange.com – Mehdi Dehghani Aug 03 '18 at 04:55
  • @MehdiDehghani I'm not so sure. The question appears to ask why this approach isn't favoured, which is something Code Review doesn't deal in. – Mast Aug 03 '18 at 05:42
  • 1
    I second @Mast. I just want to know if this approach has some drawbacks due to which it is not used commonly. For me it is simple method. I don't understand why developers choose a difficult and long path of doing the same thing. – e-malik Aug 03 '18 at 16:02

0 Answers0