
你说的这个不是浮动定位吗?
position:fixedbottom:0 left:0 width:100%
$(document).scroll(function(){if ($(window).scrollTop() > 465){
$('.nav-top').css({
position: 'fixed',
top: '0',
left:'0',
width:'100%',
})
}else{
$('.nav-top').removeAttr('style')
}
})
<html><head>
<script language="javascript">
function moveImage(){
document.getElementById("div1").style.left = 0
document.getElementById("div1").style.top = document.body.scrollTop
}
var t1 = window.setInterval("moveImage()",100)
</script>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />
<title>图片位移</title>
</head>
<body bgcolor="#CCCC00">
<div id="div1" style="position:absolute"><img src="images/hair.png" id="image1" /></div>
</body>
</html>
上面的是你的要求。下面是一个小例子。可以实现图片在页面上滚动。
<script language="javascript">
var left = 0
var top = 0
function moveImage(){
if(left >(document.body.clientWidth)-(document.getElementById("div1").offsetWidth)-4){
left = -left
}
if(top >(document.body.clientHeight)-(document.getElementById("div1").offsetHeight)-4){
top = -top
}
left += 4
top += 4
document.getElementById("div1").style.left = Math.abs(left)
document.getElementById("div1").style.top = Math.abs(top)
}
var t1 = window.setInterval("moveImage()",100)
</script>
随滚动而滚动,css就可以实现,也就是固定在屏幕固定位置,用 position:fixed即可,关闭按钮可以用document.getElementById('').style.display='none'即可,如<div style="width:500pxheight:200pxbackground-color:#F00position:fixedleft:100pxtop:200px" id="test">
<button onclick="document.getElementById('test').style.display='none'">关闭</button>
</div>
其中left和top都是相对于屏幕的位置
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)