A pop-up Layer Code

Source: Internet
Author: User
// Function getBrowser (_ B) {_ B = _ B. toString (). toLowerCase (); return (navigator. userAgent. toLowerCase (). indexOf (_ B )! =-1 )? True: false;}/* Global Method to fix Mask Overlay Height & Width */function fixMaskLayer (_ o) {if (getBrowser ("msie 6 ")) {var o = $ (_ o); var relWidth; var relHeight; var wHeight; if (document.doc umentElement & document.doc umentElement. clientHeight) {var doc = document.doc umentElement; relWidth = (doc. clientWidth> doc. scrollWidth )? Doc. clientWidth-1: doc. scrollWidth; relHeight = (doc. clientHeight> doc. scrollHeight )? Doc. clientHeight: doc. scrollHeight; wHeight = doc. clientHeight;} else {var doc = document. body; relWidth = (window. innerWidth> doc. scrollWidth )? Window. innerWidth: doc. scrollWidth; relHeight = (window. innerHeight> doc. scrollHeight )? Window. innerHeight: doc. scrollHeight; wHeight = relHeight;} o.css ({width: relWidth, height: wHeight}) ;}// Mousewheel Plugin (function ($) {$. event. special. mousewheel = {setup: function () {var handler = $. event. special. mousewheel. handler; // Fix pageX, pageY, clientX and clientY for each illaif ($. browser. mozilla) $ (this ). bind ('mousemove. mousewheel ', function (event) {$. data (this, 'mwcursorposdata', {pageX: Event. pageX, pageY: event. pageY, clientX: event. clientX, clientY: event. clientY}) ;}); if (this. addEventListener) this. addEventListener ($. browser. mozilla? 'Dommousescroll': 'mousewheel '), handler, false); elsethis. onmousewheel = handler;}, teardown: function () {var handler = $. event. special. mousewheel. handler; $ (this ). unbind ('mousemove. mousewheel '); if (this. removeEventListener) this. removeEventListener ($. browser. mozilla? 'Dommousescroll': 'mousewheel '), handler, false); elsethis. onmousewheel = function () {}; $. removeData (this, 'mwcursorposdata');}, handler: function (event) {var args = Array. prototype. slice. call (arguments, 1); event = $. event. fix (event | window. event); // Get correct pageX, pageY, clientX and clientY for mozilla $. extend (event, $. data (this, 'mwcursorposdata') | |{}); var delta = 0, returnValue = true; If (event. wheelDelta) delta = event. maid/120; if (event. detail) delta =-event. detail/3; // if ($. browser. opera) delta =-event. wheelDelta; event. data = event. data ||{}; event. type = "mousewheel"; // Add delta to the front of the argumentsargs. unshift (delta); // Add event to the front of the argumentsargs. unshift (event); return $. event. handle. apply (this, args) ;};$. fn. extend ({mousewheel: fun Ction (fn) {return fn? This. bind ("mousewheel", fn): this. trigger ("mousewheel") ;}, unmousewheel: function (fn) {return this. unbind ("mousewheel", fn) ;}}) ;}( jQuery);/* Global Popup LayerDemo: popWin ("# popID ",{...}); popWin (myPopWin ,{...}); var pop = popWin ("# popID", {action: "in" | "out", // optional. It is used to directly pop in during initialization. | it is displayed. For details, refer to obj. fn. popIn () | obj. fn. the popOut () method cannot use both the animate: true | false, // optional speed: 200, // The bounce speed | the bounce speed. Optional options include overlay: String | object // Option olSpeed: 200, // fadeIn of the mask layer | fadeOut speed, option beforeStart: funciton (), // method executed before the window pops up callOnce: funciton (), // The method callback: funciton () that needs to be executed after the first window action is completed, // The method afterPopOut: function that is executed after the window action is completed, // method executed after the action is completed in the pop-up window} pop. fn. popIn (); // call the internal method, without easing, directly pop. fn. popOut (); // call the internal method without easing. pop is displayed directly. fn. popIn (true); // call the internal method. The animation is flushed into pop. fn. popOut (true); // call the internal method. The animation is slow. */function PopWin (_ o, _ settings) {var self = this; if (! (Self instanceof PopWin) {return new PopWin (_ o, _ settings);} var o =$ (_ o); var ol = null; var settings = {}; var _ default = {x :( $ (window ). width ()-o. outerWidth ()/2, y :( $ (window ). height ()-o. outerHeight ()/2, action: "in", animate: false, speed: 200, overlay: "# overlay", olSpeed: 200, olOpacity: 0.7, queue: false, beforeStart: function () {}, callOnce: function () {}, callback: function () {}, afterPopOut: functi On () {}}_ default. y = (document.doc umentElement. scrollTop? Document.doc umentElement. scrollTop: document. body. scrollTop) + (_ default. y> 0 )? _ Default. y: 0); if (_ settings) {for (var v in _ settings) {_ default [v] = _ settings [v]; // Overwite defaults settings if customed parameters parsed in} settings = _ default; ol = $ (settings. overlay); // Overlay DOM Obj // fix functionsvar fixFunc = {preventScroll: function () {return false ;}, preventResize: function () {return false ;}}; // funciton initself. initDOM = function () {// overlay styleif (ol. length = 0) {ol = $ ('<Div id = "overlay" style = "position: fixed; top: 0; left: 0; right: 0; bottom: 0; "> </div> '); if (getBrowser (" msie 6 ") {ol = $ (' <div id =" overlay "style =" position: absolute; left: 0; width: 0; height: 0; "></div> ') ;}$ (" body "). append (ol); var olBgColor = ol.css ("backgroundColor"), olBgImg = ol.css ("backgroundImage"), olBgRpt = ol.css ("backgroundRepeat "), olBgPst = ol.css ("backgroundPosition"); olBgColor = (olBgColor )? OlBgColor: "#000"; olBgImg = (olBgImg )? OlBgImg: "url (base64: *. gif)"; olBgRpt = (olBgRpt )? OlBgRpt: "repeat"; olBgPst = (olBgPst )? OlBgPst: "left top" ;ol.css ({backgroundColor: olBgColor, backgroundImage: olBgImg, backgroundRepeat: olBgRpt, backgroundPosition: olBgPst });} else {if (getBrowser ("msie 6" contains multiple indexes ol.css ("left", 0);}elseolol.css ({top: 0, left: 0, right: 0, bottom: 0 });}} // Pop Window styleif (o. length! {Left: "50%", top: 0-o. outerHeight (), marginLeft: 0-o. outerWidth ()/2});if(o.css ("zIndex") = "auto" | o.css ("zIndex ") = 0){o.css ("zIndex", 1000)}}ol.css ("zIndex", parseint(o.css ("zIndex")-1) ;}; // init endself. initDOM (); settings. callOnce. call (o, o, self); // function objself. fn = {popIn: function (_ a, _ fn, _ data) {if (o. attr ("moving") = "1") return false; if (o. attr ("showed") = "1") return fa Lse; settings. animate = (_! = Undefined )? _ A: settings. animate; self. fn. specialFix ("beforeIn"); // Call Customized BeforeStart Functionif (settings. beforeStart) {settings. beforeStart. call (o, o, _ data);} if (settings. animate = true) {self. fn. domMouseWheel (false); o. attr ("moving", "1" specify multiple fixmasklayer(ol1_ol.css ({opacity: 0, display: "block "}). animate ({opacity: settings. olOpacity, duration: settings.olspeed.pdf, function({{o.css ("top", self. fn. getEndPos (). InY ). show (). animate ({top: self. fn. getEndPos (). y}, {duration: settings. speed, queue: settings. queue, complete: function () {// Call Customized Callback Functionsettings. callback. call (o, o); (typeof _ fn = "function ")? _ Fn. call (o, o): ''; o. attr ("showed", "1"); o. attr ("moving", "0"); self. fn. addEvent (); self. fn. domMouseWheel (true) ;}} else appsol.css ({opacity: settings. olOpacity, display: "block" contains invalid fixmasklayer(ol1_0000o.show().css ({top: self. fn. getEndPos (). y}); // Call Customized BeforeStart Functionsettings. callback. call (o, o); (typeof _ fn = "function ")? _ Fn. call (o, o): ''; o. attr ("showed", "1"); o. attr ("moving", "0"); self. fn. addEvent () ;}}, // popIn EndpopOut: function (_ a, _ fn) {if (o. attr ("moving") = "1") return false; if (o. attr ("showed ")! = "1") return false; settings. animate = (_! = Undefined )? _ A: settings. animate; if (settings. animate = true) {self. fn. domMouseWheel (false); o. attr ("moving", "1 "). show (). animate ({top: self. fn. getEndPos (). outY}, {duration: settings. speed, queue: settings. queue, complete: function () {// Call Customized Callback Functiono. hide (). attr ("showed", "0"); o. attr ("moving", "0"); // ol.fadeout(settings.olspeed,function(width {ol.css ("width", "100%")}); ol. fadeOut (settings. olSpeed); s Ettings. afterPopOut. call (o, o); (typeof _ fn = "function ")? _ Fn. call (o, o): ''; self. fn. specialFix ("afterOut"); self. fn. domMouseWheel (true) ;}}) ;}else javaso.show().css ({top: 0-self. fn. getEndPos (). y, display: "none"}); // Call Customized BeforeStart Functiono. attr ("showed", "0"); o. attr ("moving", "0"); // ol.css ("width", "100% "). hide (); ol. hide (); settings. afterPopOut. call (o, o); (typeof _ fn = "function ")? _ Fn. call (o, o): ''; self. fn. specialFix ("afterOut") ;}}, // popopout endgetEndPos: function () {var st = (document.doc umentElement. scrollTop? Document.doc umentElement. scrollTop: document. body. scrollTop); // var sl = (document.doc umentElement. scrollLeft? Document.doc umentElement. scrollLeft: document. body. scrollLeft); var win = $ (window); var _ y = (win. height ()-o. outerHeight ()/2; // var _ x = (win. width ()-o. outerWidth ()/2; return {// x: sl + (_ x> 0 )? _ X: 0), y: st + (_ y> 0 )? _ Y: 0), // curTop: st, inY: 0-o. outerHeight () + st, outY: 0-o. outerHeight () + st }}, // getEndPos endaddEvent: // events which runs after popWindow finishing Entering function () {// When Scroll & Resize Window, reposition the PopWindow $ (window ). bind ("resize scroll", function (e) {(e. type = "resize") & fixMaskLayer (ol); self. fn. rePosition () ;}); // More Events cocould happen here .... //.....}, // addEvent End RePosition: function (_ a) {// if (o. attr ("moving") = "1") return false; if (o. attr ("showed ")! = "1") return false; settings. animate = (_! = Undefined )? _ A: settings. animate; if (settings. animate = true) {o. attr ("moving", "1"); o. show (). animate ({top: self. fn. getEndPos (). y}, {duration: 200, queue: settings. queue, complete: function () {o. attr ("moving", "0") ;}}) ;}else demoo.show(demo.css ({top: self. fn. getEndPos (). y}); o. attr ("moving", "0") ;}}, // rePostion enddomMouseWheel: function (_ f) {if (_ f = false) {$ (window ). bind ("resize", fixFunc. preventResize); $ (document ). bind ("Mousewheel", fixFunc. preventScroll);} else {$ (window ). unbind ("resize", fixFunc. preventResize); $ (document ). unbind ("mousewheel", fixFunc. preventScroll) ;}}, specialFix: // Special Fix Events which runs Before popIn & After popOutfunction (_ f) {if (getBrowser ("msie 6 ")) {var v = (_ f = "beforeIn ")? "Hidden": "visible"; for (var I = 0, selects = document. getElementsByTagName ("select"); I <selects. length; I ++) {selects [I]. style. visibility = v ;}// More Special Fix cocould happens here .... //.....} // specialFix end} // fn end // Bind click Event to Close Icono. find (". close "). bind ("click", function () {self. fn. popOut (settings. animate) ;}); if (_ settings) {// when initializing an object, if the parameter sets the action to "in" | "out ", then execute the corresponding pop-up | the pop-up action (_ setting S. action = "in ")? Self. fn. popIn (_ settings. animate): ""; (_ settings. action = "out ")? Self. fn. popOut (_ settings. animate): "";} return self ;}

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.