Home > Article > Web Front-end > jquery implements sliding effects code_jquery
In the project, there is a need to use jquery to achieve the sliding effect, so the relevant content is organized as follows. The following introduction is very detailed, with text description and code analysis. Friends who need it can come and learn.
Implementation method one:
.slideUp([duration][,complete])——The target element slides up and is hidden;
.slideDown([duration][,complete])——The target element slides down to display;
.slideToggle([duration][,complete])——If the target element is hidden, slide down to display it, otherwise slide up to hide it;
Note: duration is the time interval for method execution, and complete is the callback function.
<!DOCTYPE html> <html lang="zh_CN"> <head> <meta charset="UTF-8"> <title>滑动效果</title> <script src="js/jquery-2.1.3.min.js"></script> <script src="js/slide.js"></script> <style> img{ width:500px; } </style> </head> <body> <div> <div> <button id="btn1">向上划入隐藏</button> <button id="btn2">向下滑出显示</button> <button id="btn3">向上划入隐藏/向下滑出显示</button> </div> <img src="images/2.jpg"/> </div> </body> </html>
slide.js code:
/*滑动效果*/ $(document).ready(function(){ //向上滑入 $('#btn1').click(function(){ $('img').slideUp(2000); }); //向下滑出 $('#btn2').click(function(){ $('img').slideDown(2000); }); //切换滑动 $('#btn3').click(function(){ $('img').slideToggle(2000); }); })
Implementation method two:
1. jQuery___ effect (sliding effect)
slideDown(speed, [callback])
Overview
Dynamically displays all matching elements by changing their height (increasing downward), optionally triggering a callback function after the display is complete.
This animation effect only adjusts the height of the element, allowing matching elements to be displayed in a "sliding" manner. In jQuery 1.3, the upper and lower padding and margin will also be animated, and the effect will be smoother.
Parameters
speedString,Number
A string of one of three predetermined speeds ("slow", "normal", or "fast") or a millisecond value representing the animation duration (such as: 1000)
callback (optional)FunctionFunction
Function executed when animation completes
Example
Description:
Slowly slide the paragraph down in 600 milliseconds
jQuery code:
$("p").slideDown("slow");
Description:
Use 200 milliseconds to quickly slide down the paragraph, and then a dialog box will pop up
jQuery code:
$("p").slideDown("fast",function(){ alert("Animation Done."); });
slideUp(speed, [callback])
Overview
Dynamicly hide all matching elements by changing their height (decreasing upwards), optionally triggering a callback function after hiding is complete.
This animation effect only adjusts the height of the element, allowing matching elements to be hidden in a "sliding" manner. In jQuery 1.3, the upper and lower padding and margin will also be animated, and the effect will be smoother.
Parameters
speedString,Number
A string of one of three predetermined speeds ("slow", "normal", or "fast") or a millisecond value representing the animation duration (such as: 1000)
callback (optional)Function
Function executed when animation completes
Example
Description:
Slowly slide the paragraph up in 600 milliseconds
jQuery code:
$("p").slideUp("slow");
Description:
Use 200 milliseconds to quickly slide the paragraph up, and then a dialog box will pop up
jQuery code:
$("p").slideUp("fast",function(){ alert("Animation Done."); });
slideToggle(speed, [callback])
Overview
Toggles the visibility of all matching elements via a height change, and optionally triggers a callback function when the toggle is complete.
This animation effect only adjusts the height of the element, allowing matching elements to be hidden or displayed in a "sliding" manner. In jQuery 1.3, the upper and lower padding and margin will also be animated, and the effect will be smoother.
Parameters
speedString,Number
A string of one of three predetermined speeds ("slow", "normal", or "fast") or a millisecond value representing the animation duration (such as: 1000)
callback (optional)Function
Function executed when animation completes
Example
Description:
Slowly slide the paragraph up or down for 600 milliseconds
jQuery code:
$("p").slideToggle("slow");
Description:
Use 200 milliseconds to quickly slide the paragraph up or down, and then a dialog box will pop up
jQuery code:
$("p").slideToggle("fast",function(){ alert("Animation Done."); });
The above content is the jquery code to implement sliding effects. I hope you like it.