Intent to mimic JQ operation and get a personal toolbox, constantly improve the code are personal groping, so there will certainly be a lot of deficiencies, I hope readers can put forward.
1 varXzhutils = {2 //Add a class-----DOM object-----3 //[email protected]: obj DOM object4 //[email protected]: CLS-Added classes5AddClass:function(obj, cls) {6 varOcls =Obj.classname;7 if(!ocls) {8Obj.classname =CLS;9}Else{TenOcls + = "" +CLS; OneObj.classname =Ocls; A } - }, - //-----Remove a class from a DOM object----- the //[email protected]: obj DOM object - //[email protected]: CLS-Removed classes -Removeclass:function(obj, cls) { - varOcls =Obj.classname; + if(ocls) { - vararr = Ocls.split (""); + for(varIincharr) { A if(arr[i]==CLS) { atArr.splice (i,1); - Break; - } - } -Ocls = Arr.join (""); -Obj.classname =Ocls; in } - }, to //-----Calculate The roll-up value----- +Scrollpos:function() { - varScrollpos; the if(typeofWindow.pageyoffset! = ' undefined '){ *Scrollpos =Window.pageyoffset; $}Else if(typeofDocument.compatmode! = ' undefined ' && document.compatmode! = ' Backcompat '){ Panax NotoginsengScrollpos =Document.documentElement.scrollTop; -}Else if(typeofDocument.body! = ' undefined '){ theScrollpos =Document.body.scrollTop; + } A returnScrollpos; the }, + //-----Get the next sibling node----- - //[email protected]: EVENTOBJ DOM object to get the next sibling node $ //[Email protected]: X eventobj's next sibling node $Next:function(EVENTOBJ) { - varE =EVENTOBJ; - varx =e.nextsibling; the while(x.nodetype!=1){ -x =x.nextsibling;Wuyi } the returnx; - } Wu}
Some small attempts at native JS