top小火箭
// my.js
function $(id){return document.getElementById(id)};
function show(obj){obj.style.display = "block"};
function hide(obj){obj.style.display = "none"};
function scroll(){
if(window.pageYOffset != null){// ie9 和以上的版本浏览器
return {
left: window.pageXOffset,
top: window.pageYOffset
}
}
else if(document.compatMode == "CSS1Compat"){// 声明了DTD的都支持
return {
left: document.documentElement.scrollLeft,
top: document.documentElement.scrollTop
}
}
return {// 剩下的就是怪异模式
left: document.body.scrollLeft,
top: document.body.scrollTop
}
}
// 上面 为引用,下面写效果
var pic = $("pic");
window.onscroll = function(){
scroll().top>0 ? show(pic) : hide(pic);
leader = scroll().top;
}
var leader=0, target=0, timer = null;
pic.onclick = function(){
target = 0;
timer = setInterval(function(){
leader = leader + (target - leader) / 10;
window.scrollTo(0,leader);
if(leader == target){
clearInterval(timer);
}
},20);
}
上一篇: 打电话捉奸
下一篇: 事件冒泡 比bubble