仅在一个方向上的固定位置 [英] Fixed position in only one direction

查看:164
本文介绍了仅在一个方向上的固定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想有一个固定在页面底部的项目,但是当视图水平滚动时,它也应该水平滚动。

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.

我可以使用JavaScript来实现这个功能,但是有没有CSS方法呢?

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.

推荐答案

CSS部分:

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

jQuery部分:

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

这篇关于仅在一个方向上的固定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆