Jquery——hover與toggle


hover方法的語法結構為:hover(enter,leave)

hover()當鼠標移動到元素上時,會觸發第一個方法,當鼠標移開的時候會觸發第二個方法



復制代碼
<html>
    <head>
        <title>測試用</title>
        <script type="text/javascript" src="../jquery-1.3.2.min.js"></script>
        <script type="text/javascript">
            window.onload=init;
            function init(){
                $("#panel h5.head").hover(function(){
                    $(this).next().hide();
                },function(){
                    $(this).next("div .content").show();
                });
            }
        </script>

    </head>
    <body>
    <div id="panel">
        <h5 class="head">什么事jquery</h5>
        <div class="content">
             混蛋
        </div>
    </div>

    </body>
</html>

復制代碼


toggle(fn1,fn2,fn3..)這個方法是每次單擊調用下一個方法,如果方法是最后一個,那么從第一個開始

如果只有2個方法,則是互相切換效果。


復制代碼
<html>
    <head>
        <title>測試用</title>
        <script type="text/javascript" src="../jquery-1.3.2.min.js"></script>
        <script type="text/javascript">
            window.onload=init;
            function init(){
                $("#panel h5.head").toggle(function(){
                    $(this).addClass("highlight");
                    $(this).next().hide();
                },function(){
                    $(this).removeClass("highlight");
                    $(this).next("div .content").show();
                });
            

            }
        </script>
        <style type="text/css">
            .highlight{
                background:#ff3300;
            }
        </style>
    </head>
    <body>
    <div id="panel">
        <h5 class="head">什么事jquery</h5>
        <div class="content">
             混蛋
        </div>
    </div>

    </body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM