在博客中放置jquery代码的位置

where to put jquery codes in blogger

本文关键字:jquery 代码 位置      更新时间:2023-09-26

我得到了正确的代码,可以解决我的问题,在之前发布的问题中:如何使用jQuery让图像在滚动上淡入淡出?

var divs = $('.banner');
$(window).scroll(function(){
if($(window).scrollTop()<10){
  divs.stop(true, true).fadeIn(5000);
} else {
   divs.stop(true, true).fadeOut(5000);}
});  

现在我不明白如何在博主中实现这段代码。

如果你没有jQuery,

首先在你的<head>中包含它(这是强制性的,否则你将无法使用任何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>