[英]JQuery: .animate on $(window).scroll function
我正在使用以下代碼來為“火車時刻表”保留標簽,類似於CSS的“ fixed”屬性,以允許我垂直滾動頁面,但保持水平“固定”標簽。 該腳本可以正常工作,但我希望它看起來更流暢,我嘗試使用.animate屬性,但在這種情況下無法使其正常工作。
我可以使所有內容都可以滾動顯示,我只是希望它更流暢。 任何幫助表示贊賞。
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(window).scroll(function(){
$('#tramLabels').css({
'left': $(this).scrollLeft() +5
});
});
</script>
這也是該頁面的其余代碼;
<style type="text/css">
#tramLabels {
position: absolute;
z-index: 99;
width: 200px;
top: 0px;
left: 5px;
}
#tramTime{
position: absolute;
z-index: 0;
width: 100%;
top: 0px;
left: 10px;
}
</style>
</head>
<body>
<div id="tramLabels">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
</table>
</div>
<div id="tramTime">
<table width="900px" border="0" cellspacing="0" cellpadding="0">
</table>
</div
嘗試這個:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(window).scroll(function(){
$('#tramLabels').animate({
'left': +5
});
});
</script>
我嘗試使用.animate()和.stop()進行此操作。 http://jsfiddle.net/C2f7f/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.