如何使div向上滚动并固定在顶部 [英] how to make a div scroll up and fix at the top
本文介绍了如何使div向上滚动并固定在顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新的jquery,并希望使一个div向上滚动,并在顶部固定后,向下滚动浏览器中的特定位置,如 http://www.airbnb.com/jobs/
I am new to jquery and looking to make a div scroll up and fix at the top after i scroll down a particular position in the browser just like http://www.airbnb.com/jobs/
推荐答案
这:
$(window).scroll(function () {
var height = $('body').height();
var scrollTop = $(window).scrollTop();
if(scrollTop>500){
$('#header').css({ 'position': 'fixed', 'top' : '0' });
}
else{
$('#header').css({ 'position': 'relative', 'top': '500px'});
}
});
检查此 http://jsfiddle.net/68eXM/14/
这篇关于如何使div向上滚动并固定在顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文