JQ, 마우스 통과 알림 효과 구현

3750 단어
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Explaining the Document Object Model</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
        <script>
                $(function(){
                        var x = 10;
                        var y = 20;
                        $("a.tooltip").mouseover(function(e){
                                this.myTitle = this.title;
                                this.title = "";
                                var imgTitle = this.myTitle ? "<br />" + this.myTitle +"  " : "";
                                var tooltip = "<div id='tooltip'><img src='"+this.href+"' alt=' ' width='500' height='500' />"+imgTitle+"</div>";
                                        $("body").append(tooltip);
                                        $("#tooltip")
                                                .css({
                                                        "top": (e.pageY+y) + "px", 
                                                        "left":(e.pageX+x) + "px"
                                        }).show("fast");
                        }).mouseout(function(e){
                                this.title = this.myTitle;
                                $("#tooltip").remove();
                        }).mousemove(function(e){
                                $("#tooltip").css({
                                        "top": (e.pageY+y) + "px",
                                        "left": (e.pageX+x) + "px"
                                });
                        });
                })
        </script>
        <style>
                ul{margin: 30px auto; width:1440px;}
                ul li{float: left; padding-right: 50px; list-style: none;}
                ul li img{width: 100px; height: 100px; padding: 10px; border: 1px solid #ccc; background-color:#eee; -webkit-border-radius: 8px;}
                #tooltip{
                        position: absolute;
                        background-color: #eee;
                        border: 1px solid #999;
                        width: 500px;
                        height: 520px;
                        -webkit-border-radius: 8px;
                        font-family: " ";
                        padding: 20px;
                }
        </style>
  </head>
  <body>
        <ul>
                <li><a href="images/imac.jpg" title="  iMac" class="tooltip"><img src="images/imac.jpg" alt="  iMac" /></a></li>
                <li><a href="images/iphone.jpg" title="  iPhone" class="tooltip"><img src="images/iphone.jpg" alt="  iPhone" /></a></li>
                <li><a href="images/sb.jpg" title="   " class="tooltip"><img src="images/sb.jpg" alt="   " /></a></li>
                <li><a href="images/jp.jpg" title="   " class="tooltip"><img src="images/jp.jpg" alt="   " /></a></li>
        </ul>
  </body>
</html>

미리 보기 주소:http://90-designer.com/demo/jquery/JStest_3.html

좋은 웹페이지 즐겨찾기