亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

jQuery basic animation functions

1. Use basic animation functions

The basic animation functions are mainly divided into three categories: show, hide and toggle, all of which provide parameter-free versions. Indicates that animation switching is not applicable to the display state of the element:

$("#divPop").show();
$("#divPop").hide();
$("#divPop").toggle();

provides two parameter overloads, because the callback function can be omitted, so you can pass in a value as the only parameter as used in the opening example, then The element will be displayed/hidden with animation effects within the time specified by the parameter:

$("#divPop").show(200);
$("#divPop").hide("fast");
$("#divPop").toggle("slow");

If 200 is passed, it means that the layer will be displayed through a gradient within 200 milliseconds. The speed parameter can use three predetermined speeds One of the strings ("slow", "normal", or "fast") or the millisecond value representing the animation duration (such as: 1000).

All three functions can be passed in the callback function callback, signature As follows:

function callback() {  this; // dom element}

This in the callback function is the DOM object that executes this function. It will be executed when the animation ends.

2. Use the toggle function

#The toggle function is a more powerful function that can switch the visible state of an element. We often encounter the need The situation of using toggle. For example, you want a piece of text to display the pop-up layer when you click it for the first time, and hide the pop-up layer when you click it for the second time.

Note: The toggle() method is declared obsolete in jQuery1.8. Removed in .9; jQuery animation also has a method called toggle. Which one is called depends on the settings of the arguments passed.

We can achieve this effect by slightly modifying the opening example:

<!doctype html>
<html>
<head>
 <meta charset="utf-8"/>
 <title>jQuery - Start Animation</title>
 <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
 <script>
   $(document).ready(function() {      //動畫速度
     var speed = 500;      //綁定事件處理
     $("#btnShow").click(function(event) {        //取消事件冒泡
       event.stopPropagation();        //設置彈出層位置
       var offset = $(event.target).offset();
       $("#divPop").css({ top: offset.top + $(event.target).height() + "px", left: offset.left });        //切換彈出層的顯示狀態(tài)
       $("#divPop").toggle(speed);
     });      //單擊空白區(qū)域隱藏彈出層
     $(document).click(function(event) {
       $("#divPop").hide(speed)
     });      //單擊彈出層則自身隱藏
     $("#divPop").click(function(event) {
       $("#divPop").hide(speed)
     });
   });  </script></head><body>
 <div>
   <button id="btnShow">Display the text prompt</button>
 </div>
 <!-- 彈出層 -->
 <div id="divPop" style="background-color: #f0f0f0; border: solid 1px #000000; position: absolute; display:none; width: 300px; height: 100px;">
   <div style="text-align: center;">pop div</div>
 </div>
</body>
</html>
Continuing Learning
||
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".flip").click(function(){ $(".panel").slideToggle("slow"); }); }); </script> <style type="text/css"> div.panel,p.flip { margin:0px; padding:5px; text-align:center; background:#e5eecc; border:solid 1px #c3c3c3; } div.panel { height:120px; display:none; } </style> </head> <body> <div class="panel"> <p>php中文網(wǎng) - 領先的 php教程網(wǎng)站</p> <p>在 php中文網(wǎng),你可以找到你所需要的所有網(wǎng)站建設教程。</p> </div> <p class="flip">請點擊這里</p> </body> </html>
submitReset Code