JavaScript SDK 设计指南

marginwidth="0" s.type = 'text/javascript'; var x = document.getElementsByTagName('script')[0]; script.async = true; script.src = url; script.onload = script.onreadystatechange = function () { var rdyState = script.readyState; callback(); // detach the event handler to avoid memory leaks in IE (http://mng.bz/W8fx) script.onreadystatechange = null; } }; function once(fn, context) {
var result; return function() {
if(fn) {
result = fn.apply(context || this, arguments);
fn = null;
}
return result; };
}
// Usagevar
canOnlyFireOnce = once(function() { console.log('Fired!');});
canOnlyFireOnce(); // "Fired!"canOnlyFireOnce(); // nada

获取样式

获取行间样式

 
This is black color span


获取真正的样式



This is black color span


ref:https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle

检测当前窗口

function isElementInViewport (el) { 
//special bonus for those using jQuery
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
);
}


分享到:


相關文章: