解决方法
jQuery将允许简洁的解决方案,同时隐藏大多数浏览器差异.这是一个快速模拟,让你开始:
<script type="text/javascript"> //when the DOM has loaded $(document).ready(function() { //attach some code to the scroll event of the window object //or whatever element(s) see http://docs.jquery.com/Selectors $(window).scroll(function () { var height = $('body').height(); var scrollTop = $('body').scrollTop(); var opacity = 1; // do some math here,by placing some condition or formula if(scrollTop > 400) { opacity = 0.5; } //set the opacity of div id="someDivId" $('#someDivId').css('opacity',opacity); }); }); </script>
也可以看看:
> jQuery
> Selectors
> CSS
> Events/Scroll
> CSS/ScrollTop
> CSS/ScrollLeft