JavaScript code analysis for pop-up window effects, and javascript pop-up window
:
For more information, see the code:
Var x = 0; var idzt = new Array (); var Window = function (config) {ID does not repeat idzt [x] = "zhuiti" + x; pop-up window ID initialization, receiving parameter this. config = {width: config. width | 300, width height: config. height | 200, buttons: config. buttons | '', default: No button title: config. title | 'title', title content: config. content | 'content', content isMask: config. isMask = false? False: config. isMask | true, whether to mask isDrag: config. isDrag = false? False: config. isDrag | true, whether to move}; load the pop-up window var w = ($ (window ). width ()-this. config. width)/2; var h = ($ (window ). height ()-this. config. height)/2; var nr = "<div class = 'zhiti' id = '" + idzt [x] + "'bs ='" + x + "'style = 'width: "+ this. config. width + "px; height:" + this. config. height + "px; left:" + w + "px; top:" + h + "px; '> </div>"; $ ("body "). append (nr ); load the pop-up window title var content = "<div id = 'title" + x + "'class = 'title' bs = '" + x + "'>" + t His. config. title + "<div id = 'close" + x + "'class = 'close' bs = '" + x + "'> × </div>"; load the pop-up window content var nrh = this. config. height-75; content = content + "<div id = 'content" + x + "'bs = '" + x + "'class = 'content' style = 'width: 100%; height: "+ nrh +" px; '> "+ this. config. content + "</div> "; load button content = content + "<div id = 'btnx" + x + "'bs = '" + x + "'class = 'btnx'>" + this. config. buttons + "</div>"; Add the title, content, and buttons in the window ('{'{idzt}x}}.html (cont Ent); Create a mask layer if (this. config. isMask) {var zz = "<div id = 'zz '> </div>"; $ ("body "). append (zz); $ ("# zz" ).css ('display', 'block');} maximum and minimum limits to avoid moving to var maxX = $ (window) outside the page ). width ()-this. config. width; var maxY = $ (window ). height ()-this. config. height; var minX = 0, minY = 0; move the window if (this. config. isDrag) {move the mouse to bring up the window $ (". title "). bind ("mousedown", function (e) {var n = $ (this ). attr ("bs"); Take the ID to make the selected to the top $ (". zhti ").css ("Z-index", 3); ('{'{idzt}n}}.css ("z-index", 4); take the initial coordinate var endX = 0, move the X coordinate after the endY = 0, after moving the Y coordinate startX = Centers ("left"), the initial X coordinate startY = parseint('{'{idzt}n}}.css ("top") of the pop-up layer is displayed, and the initial Y coordinate downX = e. clientX: When the mouse is pressed, the X coordinate of the mouse is downY = e. clientY; when the mouse is pressed, the Y coordinate of the mouse is bound to the mouse moving event $ ("body "). bind ("mousemove", function (es) {endX = es. clientX-downX + startX; X coordinates move endY = es. clientY-downY + startY; Y coordinate Move the maximum and minimum limits if (endX> maxX) {endX = maxX;} else if (endX <0) {endX = 0;} if (endY> maxY) {endY = maxY;} else if (endY <0) {endY = 0;} else ('your idzt?n=}.css ("top", endY + "px"); then ("left ", endX + "px"); window. getSelection? Window. getSelection (). removeAllRanges (): document. selection. empty (); // deselect selected text}); move the mouse up to release the moving event $ ("body "). bind ("mouseup", function () {$ ("body "). unbind ("mousemove") ;}}close the window $ (". close "). click (function () {var m = this. getAttribute ("bs"); identify $ ('#' + idzt [m]). remove (); remove the pop-up window $ ('# zz '). remove (); remove mask}) x ++; add ID}
The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!