Fixed position in only one direction

做~自己de王妃 提交于 2019-12-18 18:57:08

问题


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 can hack out a means of doing this with JavaScript, but is there any CSS way to do it? I don't mind a few extra DIVs here and there.


回答1:


CSS part:

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

jQuery part:

$(window).scroll(function(){
    $('#footer').css('left','-'+$(window).scrollLeft()+'px');
});



回答2:


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...



来源:https://stackoverflow.com/questions/4176432/fixed-position-in-only-one-direction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!