摘自:JQuery侧边栏滚动
$(function() { //取得所要滚动的侧边栏 var $sidebar = $("#text-3"), //取得窗口对象 $window = $(window), //获取元素在当前视口的相对偏移。 //主要是为获得top值,以便计算是不需要偏移 offset = $sidebar.offset(), //定义默认的一个间距值,即滚动后距窗口边缘的距离 topPadding = 15; //添加窗口滚动事件的方法 $window.scroll(function() { //获取window相对滚动条顶部的偏移,然后与元素的top进行比较 //如果元素的top值小的话,说明元素需要移动! if ($window.scrollTop() > offset.top) { $sidebar.stop().animate( //先停止所有动画,然后改变元素的margin-top值 //先减去top值,然后加上自定义的边距。 {marginTop: $window.scrollTop() - offset.top + topPadding} ); } else { //否则,先停止动画,并将margin-top置0,即不需要下移了 $sidebar.stop().animate({ marginTop: 0 }); } }); });
PS:发现类似的代码都存在一个小bug,如果侧边栏的高度大于浏览器的高度(即浏览器不能完全显示侧边栏的话),那么滚动条是一直存在的,那么就可以一直一直的滚下去的…… 当然既然显示不全就应该可以滚下去,但这样的情况太特殊了呢。(我认为应该计算,滚动到一定的长度后就无须再滚了,因为下面没有其它的内容了,除了侧边栏未显示的内容而已)
2021年9月04日 17:03
This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. soap 2 day
2021年9月28日 19:00
I've confirmed decided to help a blog, which I hold been missing to achieve for a during. Sees for this short, it's really goliath! บาคาร่า 1688
2021年9月29日 01:36
After a short time you'll find what is head, everything gives a url to the pulling in page: บาคาร่า"
2021年9月29日 19:28
After a short time you'll find what is head, everything gives a url to the pulling in page: <a href="https://starvegasvip.com/%e0%b9%81%e0%b8%ad%e0%b8%9e%e0%b8%84%e0%b8%b2%e0%b8%aa%e0%b8%b4%e0%b9%82%e0%b8%99/">สล็อตออนไลน์"</a>
2021年9月29日 19:43
After a short time you'll find what is head, everything gives a url to the pulling in page: สล็อตออนไลน์"
2021年9月30日 16:07
I propose as shown by a general point of view shocking close by ensured data, in this way imagine it: บาคาร่า มือถือ
2021年9月30日 22:40
So covering away to occur over your stunning site. Your blog gets me an attracting trade of fulfilling.. Salubrious part near the scene. sagame เครดิตฟรี
2021年10月02日 16:11
Cool you make, the information is genuinely salubrious further amazing, I'll give you an interface with my scene. metamorphosis literary agency
2021年10月02日 22:05
I just thought it very well may be an approach to manage regulate oversee regulate direct control direct control direct post incase some other individual was having issues taking a gander at yet I am really upsetting on the off chance that I am allowed to put names and addresses on here. หวยฮานอย
2021年10月03日 21:07
After a short time you'll find what is head, everything gives a url to the pulling in page: หวยลาว
2021年10月03日 21:15
After a short time you'll find what is head, everything gives a url to the pulling in page: หวยลาว
2021年10月06日 00:21
Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. PGSLOT
2021年10月06日 18:43
After a short time you'll find what is head, everything gives a url to the pulling in page: slotxoฟรีเครดิต
2021年10月06日 22:50
Love to read it,Waiting For More new Update and I Already Read your Recent Post its Great Thanks. สล็อต
2021年10月09日 15:47
I just want to let you know that I just check out your site and I find it very interesting and informative.. soap2day movies
2021年10月10日 20:00
This article gives the light in which we can observe the reality. This is very nice one and gives indepth information. Thanks for this nice article. North American Bancard Agent Program
2021年10月17日 22:26
SupplyCopia reduces costs, improves outcomes, increases revenue, and delivers unprecedented visibility across the entire supply chain to propel business performance. idns for healthcare
2021年10月22日 12:09
I favor if all else fails tangling resources - you will see these people in: 우리카지노
2021年12月25日 23:48
This is a truly good site post. Not too many people would actually, the way you just did. I am really impressed that there is so much information about this subject that have been uncovered and you’ve done your best, with so much class. If wanted to know more about green smoke reviews, than by all means come in and check our stuff. <a href="https://www.alrafayglobal.com">https://www.alrafayglobal.com</a>
2022年1月30日 23:57
I went onto your blog while focusing just charmingly submits. Astounding improvement for particularly, I will be bookmarking quickly handle your full scale risings... https://www.abercrombieand-fitch.com.co/2022/01/why-hire-a-divorce-lawyer-in-dwarka.html
2022年3月20日 18:20
Howdy, I discovered your blog per Google bit searching for such really enlightening slanting toward other than your issue sees all around mistaking for me. staples near me
2022年6月13日 15:04 I propose as shown by a general point of view shocking close by ensured data, in this way imagine it: Lowes Home Improvement
2023年6月23日 19:43
<a href="https://minecraftapk18.com/">Minecraft APK</a>