<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="demo"></div>
</body>
</html>
<script>
var num =0;
var demo = document.getElementById("demo");
// window.onresize = function () {
// num++;
// demo.innerHTML = window.innerWidth || document.documentElement.clientWidth; //ie8拖动一次变化两次
// console.log(num);
// }
window.onresize = throttle(function(){
demo.innerHTML = window.innerWidth || document.documentElement.clientWidth;
num++;
console.log(num);
},300);
function throttle(fn,delay){
var timer = null;
return function () {
clearTimeout(timer);
timer= setTimeout(fn,delay);
}
}
</script>
tx6-屏幕缩放事件-闭包版函数节流
最新推荐文章于 2024-07-14 11:54:09 发布