Home > Web Front-end > JS Tutorial > body text

jquery implements sliding effects code_jquery

WBOY
Release: 2016-05-16 15:46:07
Original
1235 people have browsed it

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> 
Copy after login

slide.js code:

/*滑动效果*/ 
$(document).ready(function(){ 
 //向上滑入 
 $('#btn1').click(function(){ 
  $('img').slideUp(2000); 
 }); 
 //向下滑出 
 $('#btn2').click(function(){ 
  $('img').slideDown(2000); 
 }); 
 //切换滑动 
 $('#btn3').click(function(){ 
  $('img').slideToggle(2000); 
 }); 
}) 
Copy after login

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"); 
Copy after login

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."); 
}); 
Copy after login

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"); 
Copy after login

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."); 
}); 
Copy after login

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"); 
Copy after login

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."); 
});
Copy after login

The above content is the jquery code to implement sliding effects. I hope you like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template