[英]JQuery: .animate on $(window).scroll function
I am using the following code to keep labels for a " train time table" similar to the CSS "fixed" property to allow me to scroll the page vertically but keep the labels 'fixed' horizontally. 我正在使用以下代码来为“火车时刻表”保留标签,类似于CSS的“ fixed”属性,以允许我垂直滚动页面,但保持水平“固定”标签。 This script works fine, but I would love to see it smoother, I have tried working with the .animate property but cannot get it to work in this case.
该脚本可以正常工作,但我希望它看起来更流畅,我尝试使用.animate属性,但在这种情况下无法使其正常工作。
I can get everything working scroll wise, I just would love it to be smoother. 我可以使所有内容都可以滚动显示,我只是希望它更流畅。 Any help is appreciated.
任何帮助表示赞赏。
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(window).scroll(function(){
$('#tramLabels').css({
'left': $(this).scrollLeft() +5
});
});
</script>
Here is the rest of the code for the page as well; 这也是该页面的其余代码;
<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
Edit: I placed the code here for you to try 编辑:我在这里放置代码供您尝试
Try this: 尝试这个:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(window).scroll(function(){
$('#tramLabels').animate({
'left': +5
});
});
</script>
I tried this with .animate() and .stop(). 我尝试使用.animate()和.stop()进行此操作。 http://jsfiddle.net/C2f7f/
http://jsfiddle.net/C2f7f/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.