我要做一个随滚动条滚动的对联广告条 新学javascript,现在想要做一个随滚动条滚动的对联广告条。劳烦前辈指点一下:最好有代码并且附加说明。感谢万分!javascript 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!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">div{ width:400px; height:400px; background-color:#F00;}div.ad{ width:400px; height:200px; background-color:#0F0; position:fixed; left:50px; top:0px;}</style></head><body><div>1</div><div>1</div><div>1</div><div>1</div><div class="ad">ad</div></body></html>将广告的那个div的position设为fixed试试 用jquery获取marque的position,然后将这个position的值赋给ad <!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">div{width:400px;height:400px;background-color:#F00;}div#ad{width:400px;height:200px;background-color:#0F0;position:absolute;z-index:100;}</style><script type="text/javascript"> function getScroll(){ var x=document.documentElement.scrollLeft||document.body.scrollLeft; var y=document.documentElement.scrollTop||document.body.scrollTop; return{ 'x':x, 'y':y } } window.onscroll=function(){ var div=document.getElementById("ad"); var p=getScroll(); div.style.left=100+parseInt(p.x)+"px"; div.style.top=100+parseInt(p.y)+"px"; }</script></head><body><div>1</div><div>1</div><div>1</div><div>1</div><div id="ad" style="left:100px; top:100px;">ad</div></body></html>大体思路这样试试 直接用一楼的css样式position设为fixed就可以了 为什么一定要用js extjs显示数据 DOM方法乱谈 全局变量aaaaa如何=function Sub_RSVP(bbbbb) 的问题 window.getSelection() JS任务栏滚动效果问题 请各位帮忙看一下为什么报错!! 求助!checkbox问题?????? 关于JS点击的频率 ASP.NET Ajax 客户端框架未能加载 dwz 框架 remote 传多个参数 在线等 急!! 解析 页面中的url 关于高德地图添加标记单击显示信息窗体的问题,如下是我的代码。可是不知道哪里不对就是显示不出来,帮我看看吧,新人敬请原谅。
<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">
div{
width:400px;
height:400px;
background-color:#F00;
}
div.ad{
width:400px;
height:200px;
background-color:#0F0;
position:fixed;
left:50px;
top:0px;
}
</style>
</head><body>
<div>1</div>
<div>1</div><div>1</div><div>1</div>
<div class="ad">ad</div>
</body>
</html>
将广告的那个div的position设为fixed试试
<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">
div{
width:400px;
height:400px;
background-color:#F00;
}
div#ad{
width:400px;
height:200px;
background-color:#0F0;
position:absolute;
z-index:100;
}
</style>
<script type="text/javascript">
function getScroll(){
var x=document.documentElement.scrollLeft||document.body.scrollLeft;
var y=document.documentElement.scrollTop||document.body.scrollTop;
return{
'x':x,
'y':y
}
}
window.onscroll=function(){
var div=document.getElementById("ad");
var p=getScroll();
div.style.left=100+parseInt(p.x)+"px";
div.style.top=100+parseInt(p.y)+"px";
}
</script>
</head><body>
<div>1</div>
<div>1</div><div>1</div><div>1</div>
<div id="ad" style="left:100px; top:100px;">ad</div>
</body>
</html>
大体思路这样试试