码迷,mamicode.com
首页 > Web开发 > 详细

HTML随鼠标滚动的广告图片

时间:2014-11-06 16:31:58      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   ar   os   java   div   on   cti   

--------------------------------------------------------------------------------------------------------------

function init(){
advScroll=document.getElementById("advScroll");
if(advScroll.currentStyle){//IE
advTop=parseInt(advScroll.currentStyle.top);
}else{
advTop=parseInt(document.defaultView.getComputedStyle(advScroll,null).top);//FireFox
}
}

function move(){
advScroll.style.top=(advTop+parseInt(document.documentElement.scrollTop))+"px";
}
window.onload=init;
window.onscroll=move;

--------------------------------------------------------------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
#advScroll {
position:absolute;
left:13px;
top:128px;
width:109px;
height:122px;
z-index:1;
}
-->
</style>
<script type="text/javascript">
var advTop; //广告层的初始位置
var advScroll;
function init(){
advScroll=document.getElementById("advScroll");
if(advScroll.currentStyle){//IE
advTop=parseInt(advScroll.currentStyle.top);
}else{
advTop=parseInt(document.defaultView.getComputedStyle(advScroll,null).top);//FireFox
}
}

function move(){
advScroll.style.top=(advTop+parseInt(document.documentElement.scrollTop))+"px";
}
window.onload=init;
window.onscroll=move;
</script>
</head>

<body>
<div id="advScroll"><img src="images/adv.jpg" /></div>
<div id="top"><img src="images/main1.JPG"/></div>
<div id="main"><img src="images/main2.JPG"/></div>
<div id="bottom"><img src="images/main3.JPG"/></div>
</body>
</html>

HTML随鼠标滚动的广告图片

标签:style   http   io   ar   os   java   div   on   cti   

原文地址:http://www.cnblogs.com/xiaosen992608/p/4078736.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!