標籤: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--動畫