jquery
var $a1Top;
var $a1Obj;
$(document).ready(function(){
$a1Top=$("#ad1").css("top");
});
$(window).scroll(function(){
$("#ad1").css("top", parseInt($a1Top)+$(window).scrollTop());
});
JS
var a1Top;
var a1Obj;
function inix(){
//获取a1Top的高度
a1Obj=document.getElementById("ad1");
if(a1Obj.currentStyle){
a1Top=parseInt(a1Obj.currentStyle.top);
}
else{
a1Top=parseInt(a1Obj.getComputedStyle(a1obj,null).top);
}
}
function move(){
a1Obj.style.top=a1Top+parseInt(document.documentElement.scrollTop)+"px";
}
window.onload=inix;
window.onscroll=move;
JavaScript 和 jQuery 设置悬浮广告
最新推荐文章于 2025-08-15 09:01:53 发布