标签:origin ase data send log ora pen rem get
var viewHeight = document.documentElement.clientHeight // 可视区域的高度 function lazyload () { var eles = document.querySelectorAll(‘img[data-original][lazyload]‘) Array.prototype.forEach.call(eles, function (item, index) { var rect if (item.dataset.original === ‘‘) return; // getBoundingClientRect 返回元素的大小及其相对于视口的位置。 rect = item.getBoundingClientRect() if (rect.bottom >= 0 && rect.top < viewHeight) { !function () { var img = new Image() img.src = item.dataset.original img.onload = function () { item.src = img.src } item.removeAttribute(‘data-original‘) item.removeAttribute(‘lazyload‘) }() } }) } lazyload() document.addEventListener(‘scroll‘, lazyload)
// 使用XMLHttpRequest对象 var xmlhttprequest = new XMLHttpRequest(); xmlhttprequest.onreadystatechange = callback; xmlhttprequest.onprogress = progressCallback; xmlhttprequest.open("GET","http://image.baidu.com/mouse.jpg",true); xmlhttprequest.send(); function callback () { if (xmlhttprequest.readyState == 4 && xmlhttprequest.status==200){ var responseText = xmlhttprequest.responseText; }else{ console.log("Request was unsuccessful: " + xmlhttprequest.status); } } function progressCallback (e) { e = e || event; if (e.lengthComputable){ console.log("Received " + e.loaded + " of " + e.total + " bytes") } }
标签:origin ase data send log ora pen rem get
原文地址:https://www.cnblogs.com/wzndkj/p/12001855.html