| <! DOCTYPE html> <Html> <Head> <Meta charset = "gb2312"/> <Title> untitled document </title> <Style> <! -- Body, ul, li {margin: 0; padding: 0; font: 12px/1.5 arial ;} # List {width: 400px; margin: 10px auto ;} # List li {list-style: none; padding: 5px 0; Overflow: hidden; border-bottom: 1px dotted # ccc; Filter: alpha (opacity: 0); opacity: 0; vertical-align: middle ;} --> </Style> <Script> <! -- Window. onload = function (){ Var btn = document. getElementById ("btn "); Var con = document. getElementById ("con "); Var list = document. getElementById ("list "); Var list_li = list. getElementsByTagName ("li "); Btn. onclick = function (){ Var li = document. createElement ("li "); Li. innerHTML = con. value; Con. value = ''; If (list_li.length> = 1 ){ List. insertBefore (li, list_li [0]); } Else { List. appendChild (li ); } Var height = li. offsetHeight; Li. style. height = '0 '; Startrun (li, "height", height, function (){ Startrun (li, "opacity", "100 "); }) } } Function getstyle (obj, name ){ If (obj. currentStyle ){ Return obj. currentStyle [name]; } Else { Return getComputedStyle (obj, false) [name]; } } Function startrun (obj, attr, target, fn ){ ClearInterval (obj. timer ); Obj. timer = setInterval (function (){ Var cur = 0; If (attr = "opacity "){ Cur = Math. round (parseFloat (getstyle (obj, attr) * 100 ); } Else { Cur = parseInt (getstyle (obj, attr )); } Var speed = (target-cur)/8; Speed = speed> 0? Math. ceil (speed): Math. floor (speed ); If (cur = target ){ ClearInterval (obj. timer ); If (fn ){ Fn (); } } Else { If (attr = "opacity "){ Obj. style. filter = "alpha (opacity =" + (cur + speed) + ")"; Obj. style. opacity = (cur + speed)/100; } Else { Obj. style [attr] = cur + speed + "px "; } } }, 30) } // --> </Script> </Head> <Body> <Textarea id = "con" cols = "50" rows = "5"> </textarea> <Input id = "btn" name = "" type = "button" value = "publish"> <Ul id = "list"> </Ul> </Body> </Html> |