<img name=img1 src="arrow_l.gif" style="position:absolute;">
<script language=javascript>
var obj=document.getElementById("img1")
obj.style.left=Math.random()*1000;
obj.style.top=Math.random()*500;
</script>

解决方案 »

  1.   

    <body>
    <img name="img1" src="http://community.csdn.net/images/csdn.gif" style="position:absolute;filter:alpha(opacity=0);">
    </body>
    <script language=javascript>
    function fade(o){
    this.obj = o;
    this.offset=5;
    this.timer = null;
    this.act   = "in";
    this.action= function(){
    //alert(this.obj.tagName);
    var curOpacity = this.obj.filters.alpha.opacity;
    if( this.act == "out" )
    {
    if(curOpacity > 0)
    {
    this.obj.filters.alpha.opacity-=this.offset;
    }
    else 
    {
    this.act = "in";
    this.obj.style.left= Math.random()*800 + "px";
    this.obj.style.top = Math.random()*600 + "px";
    }
    }
    else
    {
    if(curOpacity<100)
    {
    this.obj.filters.alpha.opacity+=this.offset;
    }
    else 
    {
    this.act = "out";
    }
    }
    };
    this.play = function(){ 
    var self=this;
    var f = function(){self.action()};
    this.timer=setInterval(f,40);
    };
    this.stop = function(){
    if(this.timer) clearInterval( this.timer );
    };
    }
    var m1 = document.images[0];
    var f1 = new fade(m1);
    f1.play();
    </script>
      

  2.   

    请问寻梦的稻草人:    this.obj = o;
    this.offset=5;
    this.timer = null;
    this.act   = "in";
    这些变量中的this是什么啊?不需要用var来声明吗?我对它的用法不怎么清楚哈,麻烦你给详细说说啊???
      

  3.   

    不好意思,我以为是你每次访问的时候图象在不同的位置就可以了。
    按照你的要求最基本的代码就是下面这些,不过ice_berg16(寻梦的稻草人)的要好很多
    <img name=img1 src="haha.gif" style="position:absolute;">
    <script language=javascript>
    function show()
    {
    var obj=document.getElementById("img1")
    obj.style.left=Math.random()*1000;
    obj.style.top=Math.random()*500;
    setTimeout("show()",1000)
    }
    show()
    </script>
      

  4.   

    function fade()是一个对象
    this指定当前对象
    当创建实例的时候
    如f1 = new fade(m1);
    这时候this指为f1
      

  5.   

    ice_berg16(寻梦的稻草人)
      我想问问:
    this.play = function(){ 
    var self=this;
    var f = function(){self.action()};
    this.timer=setInterval(f,40);
    在这段程序里,如果我把var f = function(){self.action()};中的self.action改成this.action
    为什么就不行了呢?