div跟着鼠标移动

<!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" >
<head>
<style type="text/css">
#testDiv
{
     width:200px;
     height:200px;
     margin-left:50px;
     margin-top:40px;
     border:2px solid red;
    }
    #pp
    {
      position:absolute;  
        }
</style>
    <title>Untitled Page</title>
    <script src="jquery-1.7.1.js" type="text/javascript"></script>
</head>
<body>

<div id="testDiv">放在我上面</div> <div id="pp" ></div>
<script type="text/javascript">
    $(function () {
        $("#testDiv").mousemove(function (e) {
            var xx = e.originalEvent.x ;
            var yy = e.originalEvent.y;
            $("#pp").text(xx + "," + yy).css({ top: yy  + "px", left: xx  + "px" });


        });
    });
</script>

</body>
</html>

posted @ 2011-12-13 17:39  Chaoswoo  阅读(1488)  评论(0编辑  收藏  举报