Home > Article > Web Front-end > jquery hide, show event and prompt callback, fade in and out fadeToggle, slide in and slide out slideToggle, animation animate stop animation stop
1.jquery hide and show event
$("p").hide(); //隐藏事件 $("p").hide(1000); //1秒内缓慢隐藏 $("p").show(); //显示事件 $("p").toggle(); //在隐藏和显示中切换
Display prompt callback after hiding
$("p").hide(function(){ alert("提示消息已经隐藏"); }); $("p").hide(1000,function(){ alert("1s内缓慢隐藏并提示消失已经隐藏"); });
2.Fade in and out
$("#p1").fadeIn(); //淡入$("#p2").fadeIn("slow"); //缓慢淡入$("#p3").fadeIn(3000); //延迟3秒淡入 $("#p").fadeOut() //淡出 $("#p").fadeToggle() //淡入淡出 $("#p3").fadeTo("slow",0.7); //设置淡化程度 0完全消失,1不淡化
3.Slide in and slide out
$(".panel").slideDown(); //向下滑动显示class=panel的p $(".panel").slideUp("slow"); //向上收起class=panel的p $(".panel").slideToggle("slow"); //点击显示,再点击收起
Examples are as follows:
<head> <script type="text/javascript"> $(document).ready(function(){ $(".flip").click(function(){ $(".panel").slideToggle("slow"); //点击向下滑动显示p,再次点击收起 }); }); </script> <style type="text/css"> p.panel,p.flip { margin:0px; padding:5px; text-align:center; background:#e5eecc; border:solid 1px #c3c3c3; } p.panel { height:120px; display:none; /*设置隐藏的p*/ } </style> </head> <body> <p class="panel"> <p>显示隐藏的p</p> <p>请大家关注我的博客</p> </p> <p class="flip">点击显示,再次点击隐藏</p> </body>
4. Animation animate
First of all, explain why you need to call animate instead of directly modifying css properties: animate can be used to slowly modify the style and animation of p The effect is more beautiful, but directly modifying the css will cause the loading and flashing to be completed directly, and the effect is not good.
By default, the position of all HTML elements is static and cannot be moved. To manipulate position, remember to first set the element's CSS position property to relative, fixed, or absolute.
Example:
<head> <script> $(document).ready(function(){ $("button").click(function(){ $("p").animate({ left:'250px', opacity:'0.5', //淡化 height:'150px', width:'150px' //height:'+=150px', //可使用相对值 //width:'+=150px' //height:'toggle', //使用预定值,从消失到显示 //width:'toggle' }); }); }); </script> </head> <body> <button>开始动画</button> <p style="background:#98bf21;height:100px;width:100px;position:absolute;"></p> </body>
Step-by-step animation
<script> $(document).ready(function(){ $("button").click(function(){ var p=$("p"); // 定义变量 p到指定位置 p.animate({height:'300px',opacity:'0.4'},"slow"); p.animate({width:'300px',opacity:'0.8'},"slow"); p.animate({height:'100px',opacity:'0.4'},"slow"); p.animate({width:'100px',opacity:'0.8'},"slow"); }); }); </script>
5. Stop animation
$("p").stop(); //按钮会停止当前活动的动画,但允许已排队的动画向前执行。 $("p").stop(true); //按钮停止当前活动的动画,并清空动画队列;因此元素上的所有动画都会停止。 $("p").stop(true,true); //会立即完成当前活动的动画,然后停下来。
The above is the detailed content of jquery hide, show event and prompt callback, fade in and out fadeToggle, slide in and slide out slideToggle, animation animate stop animation stop. For more information, please follow other related articles on the PHP Chinese website!