//打开一个链接
window.open("www.baidu.com", "_self");
//清空页面,并写入东西
document.write("<p></p>");
window.navigator.userAgent
window.location = "www.baidu.com";
js制作侧边栏(跟随滚动)
window.resize = window.onload = window.onscroll = function() {
var oDiv = document.getElementById("div1");
//可视区顶部距离网页顶部的距离
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
//(可视区的高度 - 物体本身高度)/2
var t = (document.documentElement.clientHeight - oDiv.offsetHeight)/2;
//需要设置oDive 的position为absolute
oDiv.style.top = scrollTop + t +'px';
}
//此时拖动的时候有抖动现象
//设置position:fixed --> ie6不支持此固定定位
回到顶部按钮
window.load = function() {
var timer = null;
var bSys = true;
windwo.onscroll = function() {
if(!bSys) {
clearinterval(timer);
}
bSys = false;
}
var oBtn = document.getElementById("btn1");
oBtn.onclick = function() {
timer = setInterval(function(){
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var iSpeed = Math.floor(-scrollTop / 8);
if(scrollTop == 0) {
clearInterval(timer);
}
//系统滚动
bSys = true;
document.documentElement.scrollTop= document.body.scrollTop = scrollTop + iSpeed;
}, 30);
}
window.onscroll
}