一、window.open
栗子:阿里西西运行代码功能
var oBtn = document.getElementById('btn1');
var oTxt = document.getElementById('txt1'); oBtn.οnclick=function(){ var oNewWin = window.open('about blank','_blank'); oNewWin.document.write(oTxt.value); }二、scrollTop、offsetHeight
window.οnlοad=window.οnresize=window.οnscrοll=function(){
var oDiv = document.getElementById('div1'); var scrollTop = document.documentElement.scrollTop||document.body.scrollTop; var t = (document.documentElement.clientHeight-oDiv['offsetHeight'])/2; oDiv.style.top=scrollTop+t+'px';console.log(scrollTop+'-'+getComputedStyle(oDiv)['height']);}三、回到顶部
var oBtn = document.getElementById('btn1');
var bSys = true; var timer = null; //如何检测用户拖动滚动条 window.οnscrοll=function(){ if(!bSys){ clearInterval(timer); } bSys = false; } oBtn.οnclick=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); }