我在以前发布的问题中找到了可以解决我问题的正确代码:How do I get an image to fade in and out on a scroll using jQuery?
var divs = $('.banner');
$(window).scroll(function(){
if($(window).scrollTop()<10){
divs.stop(true, true).fadeIn(5000);
} else {
divs.stop(true, true).fadeOut(5000);}
});
现在我无法理解如何在博客中实现此代码。
答案 0 :(得分:3)
首先在你的<head>
中包含jQuery(如果你没有它)(这是必须的,否则你将无法使用任何jQuery代码)。
<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js' type='text/javascript'></script>
然后将此代码粘贴到<body>
标记
<script>
中
<script type="text/javascript">
var divs = $('.banner');
$(window).scroll(function(){
if($(window).scrollTop()<10){
divs.stop(true, true).fadeIn(5000);
} else {
divs.stop(true, true).fadeOut(5000);}
});
</script>