Always scroll a div element and not page itself

前端 未结 6 1083
梦毁少年i
梦毁少年i 2021-01-11 23:18

I have a page layout with an inner

element which contains the important stuff on the page. The important part about the design is:

6条回答
  •  既然无缘
    2021-01-11 23:30

    here is a solution that might work: (fiddle: http://jsfiddle.net/maniator/9sb2a/)

    var last_scroll = -1;
    $(window).scroll(function(e){
        if($('#content').scrollTop());
        var scroll = $('#view').data('scroll');
        if(scroll == undefined){
            $('#content').data('scroll', 5);
            scroll = $('#content').data('scroll');
        }
        else {
            $('#content').data('scroll', scroll + 5);
            scroll = $('#view').data('scroll');
        }
        /*
        console.log({
            'window scroll':$('window').scrollTop(), 
            'scroll var': scroll, 
            'view scroll':$('#view').scrollTop(),
            'view height':$('#view').height(),
            'ls': last_scroll 
        });
        //*/
        if(last_scroll != $('#content').scrollTop()){ //check for new scroll
            last_scroll = $('#content').scrollTop()
            $('#content').scrollTop($('#content').scrollTop() + scroll);
    
            $(this).scrollTop(0);
            //console.log(e, 'scrolling');
        }
    
    })
    

    It is a bit buggy but it is a start :-)

提交回复
热议问题