A simple title-like tip effect, but the actual content can be very rich. The above js is saved as tip. js, And the demo is used below.
Tip. js
The Code is as follows:
Function tips (obj, tag ){
Var tip = document. createElement ('P'), arg = arguments [2], left, top; // create tipbox
Var bodywid = document.doc umentElement. clientWidth; // You can also replace it with the container width $ (id). outerWidth ();
Var abs = obj. getElementsByTagName (tag );
Tip. className = "tip_bd ";
Obj. appendChild (tip );
For (var I = 0, len = abs. length; I Hover (abs [I], function (){
Var content = arg | this. getAttribute ('tip '), text;
Left = position (this). left, top = position (this). top;
Content? Tip. innerHTML = content: tip. innerHTML = "NO content! ";
If (left + parseInt (getStyle (tip, 'width')> bodywid) // you can determine whether the current position exceeds the maximum width.
Text = 'right: '+ (bodywid-left) + 'px; left: auto ;';
Else
Text = 'left: '+ (left + this. offsetWidth) + 'px ;';
Text + = 'top: '+ (top + this. offsetHeight) + 'px ;';
Tip.style.css Text = text;
Text = '';
Tip. style. display = 'block ';
}, Function (){
Tip. style. display = 'none ';
});
}
}
Function hover (el, fnOver, fnOut) {// move the mouse over the function
AddEvent (el, 'mouseover', fnOver );
AddEvent (el, 'mouseout', fnOut );
}
Function addEvent (el, type, fn) {// bind an event
If (el. attachEvent ){
El ['E' + type + fn] = fn; // copy element references under IE to point this to the el object instead of the window
El [type + fn] = function () {el ['E' + type + fn] (window. event );}
El. attachEvent ('on' + type, el [type + fn]);
} Else
El. addEventListener (type, fn, false );
}
Function position (el) {// absolute position of the dom Node
If (el & el. nodeType = 1)
Return {'left': el.getboundingclientrect().left?document.doc umentElement. scrollLeft, 'top': el.getboundingclientrect().top;document.doc umentElement. scrollTop };
}
Function getStyle (obj, styleName) {// get the current style attribute
If (obj. currentStyle) // ie
Return obj. currentStyle [styleName];
Else {// ff
Var $ arr = obj. ownerDocument. defaultView. getComputedStyle (obj, null );
Return $ arr [styleName];
}
}
Tips (document. getElementById ('tids'), 'A ');
A simple title-like tip effect, but the actual content can be very rich. The above js is saved as tip. js, And the demo is used below.
The Code is as follows:
Prompt box
Prompt box
I have read the IT article "30 good experiences in improving the efficiency of Web application execution" published by my team. These 30 guidelines are very useful for web development, no, I know it, but I don't know it. The following is my understanding and analysis of these Principles. Some JS performance standards have also been tested for their differences. You can download the DEMO page, if your understanding is incorrect, please advise.