如何使位置:固定div水平滚动 [英] How to make position:fixed div scroll horizontally

查看:152
本文介绍了如何使位置:固定div水平滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div与位置:固定,如下图所示。



我希望它垂直固定,但我想它水平其余内容(注意水平滚动条)。



这是否可能与CSS?或者我需要Javascript(在这种情况下,我该怎么办呢?



>

$老问题,但我也在寻找一个解决方案,并发现一个很好的简单的jquery解决方案,并认为别人可能会发现它有帮助如果没有其他:

  $(window).scroll(function(){
$('#header')。 css('left',originalLeft - $(this).scrollLeft());
});

标题是div,而originalLeft是,原来的left:position。如果有人滚动,然后缩小,这也会工作,这样它会去你想要的地方。


I have a div with position:fixed, as the image below suggests.

I want it to be fixed vertically, but I want it to scroll horizontally with the rest of the content (notice the horizontal scroll bar).

Is this possible with CSS? Or do I need Javascript (in this case, how could I do it)?

解决方案

Old question, but I was also looking for a solution also, and found a nice simple jquery solution, and figured someone else might find it helpful if nothing else:

    $(window).scroll(function(){
        $('#header').css('left', originalLeft - $(this).scrollLeft());
    });

with header being the div, and originalLeft being, well, the initial left:position. This also works if someone scrolls and then zooms out, such that it would go where you would want it to.

这篇关于如何使位置:固定div水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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