1 //encapsulation function InsertAfter; function similar to insertbefore ();2 3 vardiv = document.getelementsbytagname ("div") [0];4 varspan = document.createelement ("span");5 varA = document.getElementsByTagName ("a") [0];6 Div.appendchild (span);7 8HTMLElement.prototype.insertAfter =function(tag, now) {9 if(now.nextSibling.nextSibling) {Ten This. InsertBefore (tag, now.nextSibling.nextSibling) One}Else{ A This. AppendChild (TAG) - } - the }; - Div.insertafter (span, a); - - //reverses the node within the target node + - vardiv = document.getelementsbytagname ("div") [0]; +HTMLElement.prototype.reverse =function () { A varLen = This. children.length; at Console.log (len); - while(len) { - This. InsertBefore ( This. LastChild, This. firstchild); -Len--; - } - } in Div.reverse () - to //get the Compatibility method for window scroll bars + functionGetscrolloffset () { - if(window.pagexoffset) { the return { * X:window.pagexoffset, $ Y:window.pageyoffsetPanax Notoginseng } -}Else{ the return { +X:document.body.scrollleft +Document.documentElement.scrollLeft, AX:document.body.scrolltop +Document.documentElement.scrollTop, the + } - } $ } $ - //get a Compatibility method for window dimensions - functionGetviewportoffset () { the if(window.innerwidth) { - return {Wuyi W:window.innerwidth, the W:window.innerheight - } Wu}Else{ - if(Documen.compatmode = = = "Backcompat"){ About return { $ W:document.body.clientwidth, - H:document.body.clientheight - } -}Else { A return { + W:document.documentelement.clientwidth, the H:document.documentelement.clientheight - } $ } the } the}
Self-encapsulated JS tool