var intersectionObserver = new IntersectionObserver( function (entries) { // 如果不可见,就返回 if (entries[0].intersectionRatio <= 0) return; loadItems(10); console.log('Loaded new items'); });
/* Then style the iframe to fit in the container div with full height and width */ .responsive-iframe { position: absolute; top: 0; left: 0; bottom: 0; right: 0; width: 100%; height: 100%; }
class add active
1 2 3 4 5 6 7 8 9 10 11 12 13
for (var i = 0; i < btns.length; i++) { btns[i].addEventListener("click", function() { var current = document.getElementsByClassName("active");
// If there's no active class if (current.length > 0) { current[0].className = current[0].className.replace(" active", ""); }
// Add the active class to the current/clicked button this.className += " active"; }); }
Get Element in Iframe
1 2 3
var iframe = document.getElementById("myFrame"); var elmnt = iframe.contentWindow.document.getElementsByTagName("H1")[0]; elmnt.style.display = "none";
Media Queries with JavaScrip
1 2 3 4 5 6 7 8 9 10 11
function myFunction(x) { if (x.matches) { // If media query matches document.body.style.backgroundColor = "yellow"; } else { document.body.style.backgroundColor = "pink"; } }
var x = window.matchMedia("(max-width: 700px)") myFunction(x) // Call listener function at run time x.addListener(myFunction) // Attach listener function on state changes