jQuery练习之图片跟随

<!DOCTYPE html>
<html>
    <head>
    <meta charset="UTF-8">
    <style>
        body{
          text-align:center;
        }
        #small{
            margin-top:40px;
        }
        #showBig{
            position:absolute;
            display:none;
        }
    </style>
    <!--引入jQuery库-->
    <script type="text/javascript" src="../lib/jquery-1.7.2.js"></script>
    <script type="text/javascript">
      
    $(function(){
        $("#small").bind("mouseover mouseout mousemove",function(event){
            if(event.type=="mouseover"){
                $("#showBig").show();
            }
            else if(event.type=="mouseout"){
                $("#showBig").hide();
            }
            else if(event.type=="mousemove"){
                $("#showBig").offset({
                    left: event.pageX+50,
                    top: event.pageY+50 
                });
            }
        });
    });
    </script>
    </head>
    <body>
        <img id="small" src="../img/small.jpg">
        <div id="showBig">
            <img src="../img/big.jpg" width="300px" height="300px">
        </div>
    </body>
</html>

posted @ 2021-04-27 22:14  ice--cream  阅读(38)  评论(0编辑  收藏  举报