125、蜜蜂跟随花盆采蜜

125、蜜蜂跟随花盆采蜜

脚本说明:

第一步:把如下代码加入<body>区域中

<SCRIPT language=JavaScript>

function DynLayer(id,nestref,frame) {

       if (!is.ns5 && !DynLayer.set && !frame) DynLayerInit()

       this.frame = frame || self

       if (is.ns) {

              if (is.ns4) {

                     if (!frame) {

                            if (!nestref) var nestref = DynLayer.nestRefArray[id]

                            if (!DynLayerTest(id,nestref)) return

                            this.css = (nestref)? eval("document."+nestref+".document."+id) : document.layers[id]

                     }

                     else this.css = (nestref)? eval("frame.document."+nestref+".document."+id) : frame.document.layers[id]

                     this.elm = this.event = this.css

                     this.doc = this.css.document

              }

              else if (is.ns5) {

                     this.elm = document.getElementById(id)

                     this.css = this.elm.style

                     this.doc = document

              }

              this.x = this.css.left

              this.y = this.css.top

              this.w = this.css.clip.width

              this.h = this.css.clip.height

       }

       else if (is.ie) {

              this.elm = this.event = this.frame.document.all[id]

              this.css = this.frame.document.all[id].style

              this.doc = document

              this.x = this.elm.offsetLeft

              this.y = this.elm.offsetTop

              this.w = (is.ie4)? this.css.pixelWidth : this.elm.offsetWidth

              this.h = (is.ie4)? this.css.pixelHeight : this.elm.offsetHeight

       }

       this.id = id

       this.nestref = nestref

       this.obj = id + "DynLayer"

       eval(this.obj + "=this")

}

function DynLayerMoveTo(x,y) {

       if (x!=null) {

              this.x = x

              if (is.ns) this.css.left = this.x

              else this.css.pixelLeft = this.x

       }

       if (y!=null) {

              this.y = y

              if (is.ns) this.css.top = this.y

              else this.css.pixelTop = this.y

       }

}

function DynLayerMoveBy(x,y) {

       this.moveTo(this.x+x,this.y+y)

}

function DynLayerShow() {

       this.css.visibility = (is.ns4)? "show" : "visible"

}

function DynLayerHide() {

       this.css.visibility = (is.ns4)? "hide" : "hidden"

}

DynLayer.prototype.moveTo = DynLayerMoveTo

DynLayer.prototype.moveBy = DynLayerMoveBy

DynLayer.prototype.show = DynLayerShow

DynLayer.prototype.hide = DynLayerHide

DynLayerTest = new Function('return true')

 

// DynLayerInit Function

function DynLayerInit(nestref) {

       if (!DynLayer.set) DynLayer.set = true

       if (is.ns) {

              if (nestref) ref = eval('document.'+nestref+'.document')

              else {nestref = ''; ref = document;}

              for (var i=0; i<ref.layers.length; i++) {

                     var divname = ref.layers[i].name

                     DynLayer.nestRefArray[divname] = nestref

                     var index = divname.indexOf("Div")

                     if (index > 0) {

                            eval(divname.substr(0,index)+' = new DynLayer("'+divname+'","'+nestref+'")')

                     }

                     if (ref.layers[i].document.layers.length > 0) {

                            DynLayer.refArray[DynLayer.refArray.length] = (nestref=='')? ref.layers[i].name : nestref+'.document.'+ref.layers[i].name

                     }

              }

              if (DynLayer.refArray.i < DynLayer.refArray.length) {

                     DynLayerInit(DynLayer.refArray[DynLayer.refArray.i++])

              }

       }

       else if (is.ie) {

              for (var i=0; i<document.all.tags("DIV").length; i++) {

                     var divname = document.all.tags("DIV")[i].id

                     var index = divname.indexOf("Div")

                     if (index > 0) {

                            eval(divname.substr(0,index)+' = new DynLayer("'+divname+'")')

                     }

              }

       }

       return true

}

DynLayer.nestRefArray = new Array()

DynLayer.refArray = new Array()

DynLayer.refArray.i = 0

DynLayer.set = false

 

// Slide Methods

function DynLayerSlideTo(endx,endy,inc,speed,fn) {

       if (endx==null) endx = this.x

       if (endy==null) endy = this.y

       var distx = endx-this.x

       var disty = endy-this.y

       this.slideStart(endx,endy,distx,disty,inc,speed,fn)

}

function DynLayerSlideBy(distx,disty,inc,speed,fn) {

       var endx = this.x + distx

       var endy = this.y + disty

       this.slideStart(endx,endy,distx,disty,inc,speed,fn)

}

function DynLayerSlideStart(endx,endy,distx,disty,inc,speed,fn) {

       if (this.slideActive) return

       if (!inc) inc = 10

       if (!speed) speed = 20

       var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))/inc

       if (num==0) return

       var dx = distx/num

       var dy = disty/num

       if (!fn) fn = null

       this.slideActive = true

       this.slide(dx,dy,endx,endy,num,1,speed,fn)

}

function DynLayerSlide(dx,dy,endx,endy,num,i,speed,fn) {

       if (!this.slideActive) return

       if (i++ < num) {

              this.moveBy(dx,dy)

              this.onSlide()

              if (this.slideActive) setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+num+","+i+","+speed+",\""+fn+"\")",speed)

              else this.onSlideEnd()

       }

       else {

              this.slideActive = false

              this.moveTo(endx,endy)

              this.onSlide()

              this.onSlideEnd()

              eval(fn)

       }

}

function DynLayerSlideInit() {}

DynLayer.prototype.slideInit = DynLayerSlideInit

DynLayer.prototype.slideTo = DynLayerSlideTo

DynLayer.prototype.slideBy = DynLayerSlideBy

DynLayer.prototype.slideStart = DynLayerSlideStart

DynLayer.prototype.slide = DynLayerSlide

DynLayer.prototype.onSlide = new Function()

DynLayer.prototype.onSlideEnd = new Function()

 

// Clip Methods

function DynLayerClipInit(clipTop,clipRight,clipBottom,clipLeft) {

       if (is.ie) {

              if (arguments.length==4) this.clipTo(clipTop,clipRight,clipBottom,clipLeft)

              else if (is.ie4) this.clipTo(0,this.css.pixelWidth,this.css.pixelHeight,0)

       }

}

function DynLayerClipTo(t,r,b,l) {

       if (t==null) t = this.clipValues('t')

       if (r==null) r = this.clipValues('r')

       if (b==null) b = this.clipValues('b')

       if (l==null) l = this.clipValues('l')

       if (is.ns) {

              this.css.clip.top = t

              this.css.clip.right = r

              this.css.clip.bottom = b

              this.css.clip.left = l

       }

       else if (is.ie) this.css.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)"

}

function DynLayerClipBy(t,r,b,l) {

       this.clipTo(this.clipValues('t')+t,this.clipValues('r')+r,this.clipValues('b')+b,this.clipValues('l')+l)

}

function DynLayerClipValues(which) {

       if (is.ie) var clipv = this.css.clip.split("rect(")[1].split(")")[0].split("px")

       if (which=="t") return (is.ns)? this.css.clip.top : Number(clipv[0])

       if (which=="r") return (is.ns)? this.css.clip.right : Number(clipv[1])

       if (which=="b") return (is.ns)? this.css.clip.bottom : Number(clipv[2])

       if (which=="l") return (is.ns)? this.css.clip.left : Number(clipv[3])

}

DynLayer.prototype.clipInit = DynLayerClipInit

DynLayer.prototype.clipTo = DynLayerClipTo

DynLayer.prototype.clipBy = DynLayerClipBy

DynLayer.prototype.clipValues = DynLayerClipValues

 

// Write Method

function DynLayerWrite(html) {

       if (is.ns) {

              this.doc.open()

              this.doc.write(html)

              this.doc.close()

       }

       else if (is.ie) {

              this.event.innerHTML = html

       }

}

DynLayer.prototype.write = DynLayerWrite

 

// BrowserCheck Object

function BrowserCheck() {

       var b = navigator.appName

       if (b=="Netscape") this.b = "ns"

       else if (b=="Microsoft Internet Explorer") this.b = "ie"

       else this.b = b

       this.version = navigator.appVersion

       this.v = parseInt(this.version)

       this.ns = (this.b=="ns" && this.v>=4)

       this.ns4 = (this.b=="ns" && this.v==4)

       this.ns5 = (this.b=="ns" && this.v==5)

       this.ie = (this.b=="ie" && this.v>=4)

       this.ie4 = (this.version.indexOf('MSIE 4')>0)

       this.ie5 = (this.version.indexOf('MSIE 5')>0)

       this.min = (this.ns||this.ie)

}

is = new BrowserCheck()

 

// CSS Function

function css(id,left,top,width,height,color,vis,z,other) {

       if (id=="START") return '<STYLE TYPE="text/css">\n'

       else if (id=="END") return '</STYLE>'

       var str = (left!=null && top!=null)? '#'+id+' {position:absolute; left:'+left+'px; top:'+top+'px;' : '#'+id+' {position:relative;'

       if (arguments.length>=4 && width!=null) str += ' width:'+width+'px;'

       if (arguments.length>=5 && height!=null) {

              str += ' height:'+height+'px;'

              if (arguments.length<9 || other.indexOf('clip')==-1) str += ' clip:rect(0px '+width+'px '+height+'px 0px);'

       }

       if (arguments.length>=6 && color!=null) str += (is.ns)? ' layer-background-color:'+color+';' : ' background-color:'+color+';'

       if (arguments.length>=7 && vis!=null) str += ' visibility:'+vis+';'

       if (arguments.length>=8 && z!=null) str += ' z-index:'+z+';'

       if (arguments.length==9 && other!=null) str += ' '+other

       str += '}\n'

       return str

}

function writeCSS(str,showAlert) {

       str = css('START')+str+css('END')

       document.write(str)

       if (showAlert) alert(str)

}

 

</SCRIPT><SCRIPT language=JavaScript>

function Drag() {

       this.obj = null

       this.array = new Array()

       this.dropTargets = new Array()

       this.active = false

       this.offsetX = 0

       this.offsetY = 0

       this.zIndex = 0

       this.resort = true

       this.add = DragAdd

       this.addTargets = DragAddTargets

       this.checkTargets = DragCheckTargets

       this.targetHit == null

       this.remove = DragRemove

       this.setGrab = DragSetGrab

       this.mouseDown = DragMouseDown

       this.mouseMove = DragMouseMove

       this.mouseUp = DragMouseUp

       this.onDragStart = new Function()

       this.onDragMove = new Function()

       this.onDragEnd = new Function()

       this.onDragDrop = new Function()

}

function DragAdd() {

       for (var i=0; i<arguments.length; i++) {

              var l = this.array.length

              this.array[l] = arguments[i]

              this.array[l].dragGrab = new Array(0,this.array[l].w,this.array[l].h,0)

              this.zIndex += 1

       }

}

function DragAddTargets() {

       for (var i=0; i<arguments.length; i++) {

              var l = this.dropTargets.length

              this.dropTargets[l] = arguments[i]

              this.dropTargets[l].dragGrab = new Array(0,this.dropTargets[l].w,this.dropTargets[l].h,0)

       }

}

function DragSetGrab(dynlayer,top,right,bottom,left) {

       dynlayer.dragGrab = new Array(top,right,bottom,left)

}

function DragRemove() {

       for (var i=0; i<arguments.length; i++) {

              for (var j=0; j<this.array.length; j++) {

                     if (this.array[j]==arguments[i]) {

                            for (var k=j;k<=this.array.length-2;k++) this.array[k] = this.array[k+1]

                            this.array[this.array.length-1] = null

                            this.array.length -= 1

                            break

                     }

              }

       }

}

function DragMouseDown(x,y) {

       for (var i=this.array.length-1;i>=0;i--) {

              var lyr = this.array[i]

              if (checkWithinLayer(x,y,lyr)) {

                     this.obj = this.array[i]

                     this.offsetX = x-this.obj.x

                     this.offsetY = y-this.obj.y

                     this.active = true

                     break

              }

       }

       if (!this.active) return false

       else {

              if (this.resort) {

                     this.obj.css.zIndex = this.zIndex++

                     for (var j=i;j<=this.array.length-2;j++) this.array[j] = this.array[j+1]

                     this.array[this.array.length-1] = this.obj

              }

              this.onDragStart(x,y)

              return true

       }

}

function DragMouseMove(x,y) {

       if (!this.active) return false

       else {

              this.obj.moveTo(x-this.offsetX,y-this.offsetY)

              this.onDragMove(x,y)

              return true

       }

}

function DragMouseUp(x,y) {

       if (!this.active) return false

       else {

              this.active = false

              if (this.checkTargets()) this.onDragDrop()

              this.onDragEnd(x,y)

              return true

       }

}

function DragCheckTargets() {

       for (i in this.dropTargets) {

              var lyr = this.dropTargets[i]

              if (checkWithinLayer(lyr.x,lyr.y,this.obj) ||

              checkWithinLayer(lyr.x+lyr.w,lyr.y,this.obj) ||

              checkWithinLayer(lyr.x,lyr.y+lyr.h,this.obj) ||

              checkWithinLayer(lyr.x+lyr.w,lyr.y+lyr.h,this.obj) ||

              checkWithinLayer(this.obj.x,this.obj.y,lyr) ||

              checkWithinLayer(this.obj.x+this.obj.w,this.obj.y,lyr) ||

              checkWithinLayer(this.obj.x,this.obj.y+this.obj.h,lyr) ||

              checkWithinLayer(this.obj.x+this.obj.w,this.obj.y+this.obj.h,lyr)) {

                     this.targetHit = lyr

                     return true

              }

       }

       return false

}

 

function checkWithin(x,y,left,right,top,bottom) {

       if (x>=left && x<right && y>=top && y<bottom) return true

       else return false

}

function checkWithinLayer(x,y,lyr) {

       if (checkWithin(x,y,lyr.x+lyr.dragGrab[3],lyr.x+lyr.dragGrab[1],lyr.y+lyr.dragGrab[0],lyr.y+lyr.dragGrab[2])) return true

       else return false

}

 

// automatically define the default "drag" Drag Object

drag = new Drag()

 

</SCRIPT><SCRIPT language=JavaScript>

<!--

 

for (var i=0;i<=4;i++) {

       eval("bee_r"+i+" = new Image()")

       eval("bee_r"+i+".src = 'bee-r"+i+".gif'")

       eval("bee_l"+i+" = new Image()")

       eval("bee_l"+i+".src = 'bee-l"+i+".gif'")

}

 

 

function init() {

       flower1 = new DynLayer('flower1Div')

       bee1 = new Bee('bee1Bee',null,flower1)

      

       drag.resort = false

       drag.add(flower1)

 

       document.onmousedown = mouseDown

       document.onmousemove = mouseMove

       document.onmouseup = mouseUp

       if (is.ns) document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)

}

 

function mouseDown(e) {

       if ((is.ns && e.which!=1) || (is.ie && event.button!=1)) return true

       var x = (is.ns)? e.pageX : event.x+document.body.scrollLeft

       var y = (is.ns)? e.pageY : event.y+document.body.scrollTop

       if (drag.mouseDown(x,y)) {

              return false

       }

       else return true

}

function mouseMove(e) {

       var x = (is.ns)? e.pageX : event.x+document.body.scrollLeft

       var y = (is.ns)? e.pageY : event.y+document.body.scrollTop

       if (drag.mouseMove(x,y)) {

              bee1.startFly()

              return false

       }

       else return true

}

function mouseUp(e) {

       var x = (is.ns)? e.pageX : event.x+document.body.scrollLeft

       var y = (is.ns)? e.pageY : event.y+document.body.scrollTop

       if (drag.mouseUp()) {

              return false

       }

       else return true

}

 

function Bee(id,nestref,flower) {

       this.dynlayer = DynLayer

       this.dynlayer(id,nestref)

       this.i1 = new DynLayer(id+'i1',id)

       this.i2 = new DynLayer(id+'i2',id)

       this.flower = flower

       this.flyactive = false

       this.animactive = false

       this.animcount = 0

       this.direction = "r"

       this.animdir = 1

       this.amplitude = 35

       this.angleinc = 10

       this.hoverangle = 0

       this.centerX = this.x

       this.centerY = this.y

       this.startFly = BeeStartFly

       this.fly = BeeFly

       this.animate = BeeAnimate

       this.land = BeeLand

}

Bee.prototype = DynLayer.prototype

function BeeStartFly() {

       if (!this.flyactive) {

              var distx = Math.abs(this.x+8-this.flower.x)

              var disty = Math.abs(this.y+8-this.flower.y)

              if (Math.sqrt(Math.pow(distx,2)+Math.pow(disty,2)) > 35) {

                     this.slideActive = false

                     this.animactive = true

                     this.animate()

                     this.flyactive = true

                     this.fly()

              }

       }

}

function BeeFly() {

       if (this.flyactive) {

              var distx = Math.abs(this.x+8-this.flower.x)

              var disty = Math.abs(this.y+8-this.flower.y)

              if (Math.sqrt(Math.pow(distx,2)+Math.pow(disty,2)) > 40 || distx > 15) {

                     var angle = Math.floor(Math.atan(disty/distx)*180/Math.PI)

                     if (distx==0 && disty==0) angle = 0

                     if (this.flower.x>=this.x+8) {

                            if (this.flower.y<=this.y+8) angle = angle    // 0 to 90

                            else angle = 360-angle                // 270 to 360

                            this.direction = "r"

                     }

                     else {

                            if (this.flower.y<=this.y+8) angle = 180-angle    // 90 to 180

                            else angle = 180+angle           // 180 to 270

                            this.direction = "l"

                     }

                     this.centerX += 3*Math.cos(angle*Math.PI/180)

                     this.centerY -= 3*Math.sin(angle*Math.PI/180)

                     this.hoverangle += this.angleinc

                     this.moveTo(this.centerX,this.centerY-this.amplitude*Math.sin(this.hoverangle*Math.PI/180))

                     setTimeout(this.obj+'.fly()',20)

              }

              else {

                     this.flyactive = false

                     this.slideTo(this.flower.x+3,this.flower.y-5,2,20,this.obj+".land()")

              }

       }

}

function BeeAnimate() {

       if (this.animactive) {

              this.i1.doc.images[this.id+'i1Img'].src = eval('bee_'+this.direction+Math.floor(5*Math.random())+'.src')

              this.i2.doc.images[this.id+'i2Img'].src = eval('bee_'+this.direction+Math.floor(5*Math.random())+'.src')

              setTimeout(this.obj+'.animate()',20)

       }

}

function BeeLand() {

       this.centerX = this.x

       this.centerY = this.y

       this.hoverangle = 0

       if (!this.flyactive) {

              this.i1.doc.images[this.id+'i1Img'].src = bee_r1.src

              this.i2.doc.images[this.id+'i2Img'].src = bee_r1.src

              this.animactive = 0

       }

}

 

//-->

</SCRIPT><STYLE type=text/css>#bee1Bee {   LEFT: 100px; WIDTH: 16px; POSITION: absolute; TOP: 100px; HEIGHT: 16px}#bee1Beei1 {       LEFT: 0px; WIDTH: 16px; POSITION: absolute; TOP: 0px; HEIGHT: 16px}#bee1Beei2 {    LEFT: 0px; WIDTH: 16px; POSITION: absolute; TOP: 0px; HEIGHT: 16px}#flower1Div {     LEFT: 120px; WIDTH: 45px; POSITION: absolute; TOP: 120px; HEIGHT: 72px}</STYLE><DIV id=flower1Div><IMG height=72 src="flower.gif" width=45></DIV><DIV id=bee1Bee><DIV id=bee1Beei1><IMG height=16 src="bee-r1.gif" width=16 name=bee1Beei1Img></DIV><DIV id=bee1Beei2><IMG height=16 src="bee-r1.gif" width=16 name=bee1Beei2Img></DIV></DIV>

 

 

第二步:把<body>中的内容改为:

<body onload=init()>

 

Write a comment

Comments: 0