| <! DOCTYPE html> <Html> <Head> <Meta charset = "gb2312"/> <Title> untitled document </title> <Style> Body {margin: 0; padding: 0; font: 12px/1.5 arial; height: 2000px ;} # Jb51 {width: 100px; height: 200px; line-height: 200px; Text-align: center; border: 1 p solid # ccc; Background: # f5f5f5; position: absolute; left:-100px; top: 0 ;} # Jb51_tit {position: absolute; right:-20px; top: 60px; Width: 20px; height: 60px; padding: 10px 0; Background: # 06c; text-align: center; Line-height: 18px; color: # fff ;} </Style> <Script> Window. onload = function (){ Var jb51 = document. getElementById ("jb51 "); Jb51.onmouseover = function (){ Startrun (jb51, 0, "left ") } Jb51.onmouseout = function (){ Startrun (jb51,-100, "left ") } Window. onscroll = window. onresize = function (){ Var scrtop=document.doc umentElement. scrollTop | document. body. scrollTop; Var height=document.doc umentElement. clientHeight | document. body. clientHeight; Var top = scrtop + (height-jb51.offsetHeight)/2; Top = parseInt (top ); Startrun (jb51, top, "top ") } } Var timer = null Function startrun (obj, target, direction ){ ClearInterval (timer ); Timer = setInterval (function (){ Var speed = 0; If (direction = "left "){ Speed = (target-obj.offsetLeft)/8; Speed = speed> 0? Math. ceil (speed): Math. floor (speed ); If (obj. offsetLeft = target ){ ClearInterval (timer ); } Else { Obj. style. left = obj. offsetLeft + speed + "px "; } } If (direction = "top "){ Speed = (target-obj.offsetTop)/8; Speed = speed> 0? Math. ceil (speed): Math. floor (speed ); If (obj. offsetTop = target ){ ClearInterval (timer ); } Else { Obj. style. top = obj. offsetTop + speed + "px "; } Document. title = obj. offsetTop + ',' + target + ',' + speed; } }, 30) } </Script> </Head> <Body> <Div id = "jb51"> Shared content <Span id = "jb51_tit"> share to </span> </Div> </Body> </Html> |