DIV随屏幕滚动JS代码
var tips; var theTop = 250/*这是默认高度*/; var old = theTop; function initFloatTips() { tips = document.getElementById('floatTips'); moveTips(); }; function moveTips() { var tt=50; if (window.innerHeight) { pos = window.pageYOffset } else if (document.documentElement && document.documentElement.scrollTop) { pos = document.documentElement.scrollTop } else if (document.body) { pos = document.body.scrollTop; } pos=pos-tips.offsetTop+theTop; pos=tips.offsetTop+pos/10; if (pos < theTop) pos = theTop; if (pos != old) { tips.style.top = pos+"px"; tt=10; } old = pos; setTimeout(moveTips,tt); } $(document).ready(function(){ initFloatTips(); })
DIV的ID命名要和JS中的相对应,下面是CSS样式,大家可以自己按需要定义
div#floatTips{ position:absolute; padding:3px; bottom:0px; right:0px; z-index:9999; }
本文来源于WEB开发笔记 http://www.chhua.com , 原文地址: http://www.chhua.com/web-note2492