1、移动div

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  

<html>  

    <head>  

        <title>test2.html</title>  

        <meta http-equiv="content-type" content="text/html; charset=UTF-8">  

        <script type="text/javascript" src="js/jquery-1.3.2.js"></script>  

       <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->  

        <script type="text/javascript">  

var b = function(){   

    $("body").append("<div id='hid' style='background:red;position:absolute;width:880;height:120'>我是可以拖动的半透明div,Firefox下暂时只能获取点击事件,event无解</div>");   

    $("#hid").fadeTo("slow", 0.5);   

    $("#hid").mousedown(function(event){   

        var offset=$("#hid").offset();   

        x1=event.clientX-offset.left;   

        y1=event.clientY-offset.top;   

        $("#hid").mousemove(function(event){   

           $("#hid").css("left",(event.clientX-x1)+"px");   

            $("#hid").css("top",(event.clientY-y1)+"px");   

/*

$("#hid").animate({
left : _x + "px",
top : _y + "px"
}, 10);

*/

        });   

        $("#hid").mouseup(function(event){   

            $("#hid").unbind("mousemove");   

        });   

    });   

}   

</script>  

    </head>  

    <body>  

        <input type=button value="点我显示div" onclick="b()">  

    </body>  

</html>
View Code

相关文章:

  • 2021-10-27
  • 2022-12-23
  • 2021-07-18
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
  • 2022-02-08
  • 2022-12-23
相关资源
相似解决方案