如何让div留在另一个div的底部滚动 [英] How to make a div stay at the bottom of another div that scrolls

查看:379
本文介绍了如何让div留在另一个div的底部滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个高度为400px的div,它有内容滚动。我有另一个div与里面的图像,这个div坐在这个父div的底部使用position:absolute; bottom:0;但当我滚动它向上移动父div与内容。

I have a div that is 400px high and it has content that scrolls inside. I have another div with an image inside, this div sits at the bottom of this parent div using position:absolute; bottom:0; but when I scroll it moves up the parent div with the content.

每次用户滚动父div时,我都使用jQuery将div的位置更改为底部,但是每次div滚动时都会跳转。

I have used jQuery to change the position of the div to the bottom each time the user scrolls the parent div, this works but it jumps each time the div scrolls.

有平滑滚动的方法吗?

Is there a way to do this with a smooth scroll? I would like it to just sit at the bottom of the parent div and not move at all.

感谢

推荐答案

您可以将带有内容的div放在另一个div中,并将图像相对于父对象放置。你必须考虑到滚动条的高度,如果存在,但除此之外,它应该工作。我会尽力为你提供一个jsfiddle。

You could put the div with content inside of another div and position the image relative to the parent. You would have to account for the height of the scrollbar if present, but other than that it should work. I'll try to come up with a jsfiddle for you.

http:// jsfiddle .net / AwH9S /

您可能想要实现一些javascript来确定滚动条的大小和是否存在。

You might want to implement some javascript to determine the size of the scrollbar and whether or not it's present.

这篇关于如何让div留在另一个div的底部滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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