| <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> <Title> animation pop-up layer </title> <Style> . List { Position: relative ;; Background: # eee; Border: 1px # ccc solid; Margin: 10px; Height: 30px; Width: 100px; Cursor: pointer; } . ListShow { Position: relative; Background: # eff; Border: 1px # ddd solid; Margin: 10px; Height: 30px; Width: 100px; Cursor: pointer; } . Comment { Position: absolute; Left: 0; Display: none; Position: absolute; Border: 1px # ccc solid; Background: # background; Width: 200px; Height: 200px; Overflow: hidden; Z-index: 100; } </Style> </Head> <Body> <Div class = "" id = "show"> 0 </Div> <Div class = "list" id = "list1"> 1 <Div class = "comment" id = "comment1"> 111 <br/> </Div> <Div class = "list" id = "list2"> 2 <Div class = "comment" id = "comment2"> content display 222 </div> </Div> <Div class = "list" id = "list3"> 3 <Div class = "comment" id = "comment3"> content display 333 </div> </Div> </Body> </Html> <Script> Var zindex = 0; Function $ id (id ){ Return document. getElementById (id ); } Var Bind = function (object, fun ){ Var args = Array. prototype. slice. call (arguments). slice (2 ); Return function (){ Return fun. apply (object, args ); } } Function addEventHandler (oTarget, sEventType, fnHandler ){ If (oTarget. addEventListener ){ OTarget. addEventListener (sEventType, fnHandler, false ); } Else if (oTarget. attachEvent ){ OTarget. attachEvent ('on' + sEventType, fnHandler ); } Else {oTarget ['on' + sEventType] = fnHandler ;} } Var Shower = function (){ This. list = null; This. comment = null; This. moveLeft = 80; This. moveTop = 20; This. height = 150; This. Length = 250; This. time = 800; This. init = function (lisObj, comObj ){ This. list = lisObj; This. comment = comObj; Var _ this = this; This. _ fnMove = Bind (this, this. move ); (Function (){ Var obj = _ this; AddEventHandler (obj. list, "click", obj. _ fnMove ); })(); }; This. move = function (){ Var _ this = this; Var w = 0; Var h = 0; Var height = 0; // The height of the pop-up div Var width = 0; // The width of the pop-up div Var t = 0; Var startTime = new Date (). getTime (); // execution start time If (! _ This. comment. style. display | _ this. comment. style. display = "none "){ _ This. comment. style. display = "block "; _ This. comment. style. height = 0 + "px "; _ This. comment. style. width = 0 + "px "; _ This. list. style. zIndex = ++ zindex; _ This. list. className = "listShow "; Var comment = _ this. comment. innerHTML; _ This. comment. innerHTML = ""; // remove the display content. Var timer = setInterval (function (){ Var newTime = new Date (). getTime (); Var timestamp = newTime-startTime; _ This. comment. style. left = Math. ceil (w) + "px "; _ This. comment. style. top = Math. ceil (h) + "px "; _ This. comment. style. height = height + "px "; _ This. comment. style. width = width + "px "; T ++; Var change = (Math. pow (timestamp/_ this. time-1), 3) + 1 ); // Get the basic changes according to the running time W = _ this. moveLeft * change; H = _ this. moveTop * change; Height = _ this. height * change; Width = _ this. width * change; $ Id ("show"). innerHTML = w; If (w> _ this. moveLeft ){ ClearInterval (timer ); _ This. comment. style. left = _ this. moveLeft + "px "; _ This. comment. style. top = _ this. moveTop + "px"; _ this. comment. style. height = _ this. height + "px "; _ This. comment. style. width = _ this. width + "px "; _ This. comment. innerHTML = comment; // reply to the displayed content } }, 1, _ this. comment ); } Else { _ This. hidden (); } } This. hidden = function (){ Var _ this = this; Var flag = 1; Var hiddenTimer = setInterval (function (){ If (flag = 1 ){ _ This. comment. style. height = parseInt (_ this. comment. style. height)-10 + "px "; } Else { _ This. comment. style. width = parseInt (_ this. comment. style. width)-15 + "px "; _ This. comment. style. left = parseInt (_ this. comment. style. left) + 5 + "px "; } If (flag = 1 & parseInt (_ this. comment. style. height) <10 ){ Flag =-flag; } If (parseInt (_ this. comment. style. width) <20 ){ ClearInterval (hiddenTimer ); _ This. comment. style. left = "0px "; _ This. comment. style. top = "0px "; _ This. comment. style. height = "0px "; _ This. comment. style. width = "0px "; _ This. comment. style. display = "none "; If (_ this. list. style. zIndex = zindex ){ Zindex --; }; _ This. list. style. zIndex = 0; _ This. list. className = "list "; } }, 1) } } Window. onload = function (){ // Create menu objects Var shower1 = new Shower (); Shower1.init ($ id ("list1"), $ id ("comment1 ")); Var shower2 = new Shower (); Shower2.init ($ id ("list2"), $ id ("comment2 ")); Var shower3 = new Shower (); Shower3.init ($ id ("list3"), $ id ("comment3 ")); } </Script> |