A hundred boring cases to write, the idea of the effect comes from the pig to an address http://www.scmylike.com/wishingtree/index.html? Ran = 1293530304018. This is one of their projects. If you are interested, you can go and have some problems during the writing process. Thank you for your correction, and Jack's father helped me find out what makes people suffer from less than one letter.
JS:
Function danteng () {This. init. apply (this, arguments)}; danteng. prototype = {init: function (OPTs) {var set = {outer: 'test', width: 800, height: 400, oclass: 'hahaha', Len: 20} opts = opts | |{}; var opt = This. extend (set, opts); var box = document. getelementbyid (OPT. outer); this. maxzindex = OPT. len; For (VAR I = 0, Len = OPT. len; I <Len; I ++) {var odiv = document. createelement ('div '); var Index = This. getrandomzindex (OPT. len); odiv. Classname = OPT. oclass; box. appendchild (odiv); odiv. style. zindex = index; odiv. innerhtml = I; var width = odiv. offsetwidth, Height = odiv. offsetheight; var Pos = This. getrandompos (OPT. width-width, OPT. height-height); this. skyanimate (odiv, {'top': POS. y, 'left': POS. x}, 'low', function () {}); this. drag (odiv, OPT. width, OPT. height) }}, extend: function (baseobj, extendobj) {for (var I in extendobj) baseobj [I] = extendobj [I]; return baseobj;}, getrandomzindex: function (zindex) {return math. round (math. random () * zindex);}, getrandompos: function (left, top) {return {X: math. round (math. random () * left), Y: math. round (math. random () * Top) };}, getpos: function (e) {e = E | window. event; If (E. pagex | E. pagey) return {X: E. pagex, Y: E. pagey}; return {X: E. clientx + document.doc umentelement. scrollleft-document. body. clientleft, Y: E. clienty + docum Ent.doc umentelement. scrolltop-document. Body. clienttop };}, addevent: function (El, type, FN) {If (El. addeventlistener! = Undefined) {El. addeventlistener (type, FN, false);} else if (El. attachevent! = Undefined) {el. attachevent ('on' + type, FN)} else {El ['on' + type] = FN ;}, removeevent: function (El, type, FN) {If (El. removeeventlistener! = Undefined) {El. removeeventlistener (type, FN, false);} else if (El. detachevent! = Undefined) {el. detachevent ('on' + type, FN);} else {El ['on' + type] = function () {};}, drag: function (El, range_width, range_height) {This. addevent (El, 'mouseunder', this. down (El, range_width, range_height); El. ondragstart = function () {return false ;}}, down: function (El, range_width, range_height) {VaR _ this = This; return function (E) {var width = range_width-el. offsetwidth; var left = range_height-el. offsetheight; VA R Pos = _ this. getpos (E); var L = parseint (El. style. left); var T = parseint (El. style. top); El. style. zindex = ++ _ this. maxzindex; _ this. tmp_move = _ this. move (El, L, t, width, left, POS); _ this. tmp_up = _ this. up (EL); _ this. addevent (document, 'mousemove ', _ this. tmp_move); _ this. addevent (document, 'mouseup', _ this. tmp_up) ;}}, move: function (El, L, t, width, left, POS) {VaR _ this = This; return function (E) {var newpos = _ this. get POs (E); var OL = L + newpos. x-pos. x; var ot = T + newpos. y-pos. y; El. style. left = math. max (0, math. min (OL, width) + 'px '; El. style. top = math. max (0, math. min (OT, left) + 'px ';}}, up: function (EL) {VaR _ this = This; return function () {_ this. removeevent (document, 'mousemove ', _ this. tmp_move) ;}}, skyanimate: function (OBJ, options, step, callback) {If (! OBJ) return; var n = 0, Timer = NULL, ostyle = [], De = [], c = [], B = 0; step = {'low ': 100, 'normal': 64, 'fast ': 10} [STEP] | 64; var d = function (x) {return math. SQRT (1-math. pow (X-1), 2)} For (var I in options) {var obj_style = parseint (this. sky_css (OBJ, I); If (! Obj_style) obj_style = 0; de. push (obj_style); C. push (options [I]-obj_style); ostyle. push (I);} timer = setinterval (function () {If (n> = step) {clearinterval (timer); If (callback & callback instanceof function) callback () ;} B = D (N/step); For (VAR J = 0, Len = de. length; j <Len; j ++) {obj. style [ostyle [J] = de [J] + C [J] * B + 'px';} n ++ ;}, 15) ;}, sky_gettype: function (o) {var t; Return (t = typeof (O) = 'o Bject '? O = NULL & 'null' | (object. prototype. tostring. call (o )). slice (8,-1): T ). tolowercase () ;}, sky_css: function (O, name) {If (this. sky_gettype (name) = 'string') {If (O. style [name]) return O. style [name]; If (O. currentstyle) return O. currentstyle [name]; If (document. defaultview) return document. defaultview. getcomputedstyle (O, "") [name];} else if (this. sky_gettype (name) = 'object') {for (var I in name) {o. style [I] = Name [I] ;}}} new danteng ();
HTML:
<! 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">