Jquery--動畫

來源:互聯網
上載者:User

標籤:dota   common   anim   position   事件   判斷   定位   圖片   自訂   

 

動畫:

1、show(),hide()

2、.stop() .slideDown();  向下。 .stop().slideUp();  向上 (可以做下拉)        .stop() 執行之前加 停止

<script type="text/javascript">
$("#div1").hover(function () {/*複合事件 移入移出*/
$("#div2").stop() .slideDown();
}, function () {
$("#div2").stop().slideUp();
});
</script>

3、.fadeIn();    .fadeOut();  淡入淡出效果

4、自訂動畫:

animate({left:"300px",top:"300px"....},1000,function(){回呼函數});   1000指的是 時間(秒)

停止動畫,防止動畫積累, .stop(true)  不加true也可

<script type="text/javascript">
$("#div2").click(function () {
$(this).animate({ left: "600px", top: "300px" }, 1000, function () {
$(this).css("background-color","red"); 移動指定位置變成紅色
});
});
</script>

 

執行個體:下拉式功能表

<style type="text/css">        .div {        position:relative;        width:120px;        height:60px;        overflow:hidden;/*超出部分隱藏*/        float:left;        margin-left:10px;        }        .div1 {        position:relative;        width:120px;        height:60px;        background-color:red;               }        .div2 {        position:relative;        width:120px;        height:400px;        background-color:green;       /*display:none;隱藏*/        }    </style></head><body>    <form id="form1" runat="server">        <div class="div">           <div class="div1">   </div>           <div class="div2"></div>        </div>        <div class="div">           <div class="div1">   </div>           <div class="div2"></div>        </div>               <div class="div">           <div class="div1">   </div>           <div class="div2"></div>        </div>            </form></body></html><script type="text/javascript">    $(".div").hover(function () {        $(this).stop().animate({height:"460px"},500);    }, function () {        $(this).stop().animate({ height:"60px"}, 500);    });</script>

 

大圖滾動:

 

<style type="text/css">        .div1 {        position:relative;        width:400px;        height:400px;        left:100px;        background-color:red;        overflow:hidden;        }        #datu {        position:relative;        width:1600px;        height:100%;        }            #datu img {            position:relative;            float:left;          width:400px;          height:400px;                        }    </style></head><body>    <form id="form1" runat="server">    <div class="div1">        <div id="datu">            <img src="Images/dota_chenmo1.jpg" />            <img src="Images/dota_img3.jpg" />            <img src="Images/dota_img4.jpg" />            <img src="Images/dota_img5.jpg" />        </div>    </div>    </form></body></html><script type="text/javascript">    var count = 0;/*定義一個數為0,每點擊一下就是下一張圖*/         var time1=  window.setInterval(function () {/*自動換圖,每隔兩秒*/            count++;/*加1,加1...*/            if (count >= 4)/*判斷到了第四張再從第一張走*/ {                count = 0;            }            var pxx = count * -400;/*定義一個數,左邊多少*/            $("#datu").animate({ left: pxx }, 1000);        }, 2000);      $(".div1").mouseover(function () {          window.clearInterval(time1);      });           </script>

 

 

 

<script type="text/javascript">    var count = 0;    $("#div1").click(function () {        count++;        $("#datu").animate({ left: count * -400 }, 500, function () {            if (count >= 4) {                count = 0;                $("#datu").css("left","0");            }        });    });   </script>

 

 

 移入圖片變大:

<style type="text/css">        #div1 {        width:100px;        height:100px;        background-color:red;                }    </style></head><body>    <form id="form1" runat="server">    <div id="div1"></div>    </form></body></html><script type="text/javascript">    $("#div1").hover(function () {//滑鼠移入圖變大並且漸層色,先引入Color包引入,必須放到下面        $(this).animate({width:"300",height:"300",backgroundColor:"green"},500);    }, function () {        $(this).animate({ width: "100", height: "100", backgroundColor: "red" }, 500);    });</script>

 

Jquery--動畫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.