Last active
December 29, 2015 01:49
-
-
Save alanerzhao/7595761 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var processor = { | |
timeoutId : null, | |
performProcessing : function () { | |
}, | |
process: function () { | |
clearTimeout(this.timeoutId); | |
var that = this; | |
this.timeoutId = setTimeout(function () { | |
that.performProcessing(); | |
},100) | |
} | |
} | |
processor.process(); | |
//示例 | |
var cont = 0; | |
function resizeDiv () { | |
cont++; | |
var div = document.getElementById("cc"); | |
div.style.height = div.offsetWidth + "px"; | |
console.log(cont + "次"); | |
} | |
window.onresize = function () { | |
throttle(resizeDiv); | |
} | |
//函数节流方法,超实用 | |
function throttle(method, scope) { | |
clearTimeout(method.tId); | |
method.tId= setTimeout(function(){ | |
method.call(scope); | |
}, 100); | |
} | |
var cont = 0; | |
function resizeDiv () { | |
cont++; | |
var div = document.getElementById("cc"); | |
console.log((document.body.clientWidth - parseInt(div.style.width))); | |
div.style.left = (Math.max(document.documentElement.clientWidth,document.documentElement.scrollWidth) - parseInt(div.style.width)) / 2 + "px" | |
div.style.top = (Math.max(document.documentElement.clientHeight,document.documentElement.scrollHeight) - parseInt(div.style.height)) / 2 + "px" | |
console.log(top); | |
// div.style.height = div.offsetWidth + "px"; | |
console.log(cont + "次"); | |
} | |
window.onresize = function () { | |
throttle(resizeDiv); | |
} | |
function throttle(method, scope) { | |
clearTimeout(method.tId); | |
method.tId= setTimeout(function(){ | |
method.call(scope); | |
}, 100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment