Fixed position in only one direction

后端 未结 2 1771
[愿得一人]
[愿得一人] 2021-01-04 02:40

So, essentially, I\'d like to have an item that is fixed to the the bottom of the page, but when the view scrolls horizontally, it should horizontally scroll too.

I

相关标签:
2条回答
  • 2021-01-04 03:09

    CSS part:

    #footer {
        position:fixed;
        bottom:0px;
        left:0px
    }
    

    jQuery part:

    $(window).scroll(function(){
        $('#footer').css('left','-'+$(window).scrollLeft()+'px');
    });
    
    0 讨论(0)
  • 2021-01-04 03:28

    Really the jQuery part must be like:

    var s = $(window).scrollLeft() - scroll_old;    
    scroll_old = $(window).scrollLeft(); // initially = 0;
    var diff = left_num - s;
    var new_left = diff+"px";
    

    then like above...

    0 讨论(0)
提交回复
热议问题