我试图让我的右手列 div 向下滚动并且我遇到了一些问题,我尝试使用 position:fixed; 但我希望它保持静止,直到它滚动过去。
<script type="text/javascript">
$(document).ready(function() {
var s = $(".rightcol_infobox");
var pos = s.position();
$(window).scroll(function() {
var windowpos = $(window).scrollTop();
s.html("Distance from top:" + pos.top + "<br />Scroll position: " + windowpos);
if (windowpos >= pos.top) {
s.addClass("stick");
} else {
s.removeClass("stick");
}
});
});
</script>
看起来非常接近我想要的,但它似乎不起作用。这里是一些 css im 使用:
div.rightcol_infobox {
float:left;
margin-left:20px;
margin-top:20px;
width:283px;
padding:0px 2px 10px 2px;
background-color:#eee;
border-radius:10px
}
div.mainpage {
float:left;
clear:left;
min-width:1000px;
overflow:visible;
margin:20px 0px 0px 0px;
}
div.maincontent {
float:left;
clear:left;
width:670px;
margin-top:20px;
}
.stick {
position:fixed;
top:0px;
}
HTML:
<!-- Right-column -->
<div class="rightcol_infobox">
<script SRC="../general/Socials_Techauth.js"></script>
<div class="infobox rounded">
<P class="infoboxheading">Enquiries</p>
<p class="leftcol_text">Enquire about our technical authoring services<A href="..\enquiry\enquirytechnicalauthoring_sb.htm" rel="shadowbox;width=400;height=450"> Click here</a></p>
</div>
<div class="infobox rounded">
<P class="infoboxheading">See also</p>
<p class="leftcol_text">Why use Armada to write your online help and user guides? <A href="whyusearmada.htm"> Click here</a></p>
<script SRC="../general/socials2_techauth.js"></script>
</div>
</div>
我已经在这里呆了几天了,似乎无法破解它 http://jsfiddle.net/dHW6b/1/