Home Web Front-end JS Tutorial Summary of jQuery methods for controlling element display, hiding, switching, and sliding_jquery

Summary of jQuery methods for controlling element display, hiding, switching, and sliding_jquery

May 16, 2016 pm 04:03 PM
jquery switch show slide hide

jQuery Hide and Show

Through the two functions hide() and show(), jQuery supports hiding and showing HTML elements:
Example

Copy code The code is as follows:

$("#hide").click(function(){
$("p").hide();
});
$("#show").click(function(){
$("p").show();
});

Both hide() and show() can set two optional parameters: speed and callback.
Syntax:
Copy code The code is as follows:

$(selector).hide(speed,callback)

$(selector).show(speed,callback)


The speed parameter specifies the speed at which to show or hide. These values ​​can be set: "slow", "fast", "normal" or milliseconds.
The callback parameter is the name of the function to be executed after the hide or show function completes. You'll learn more about the callback parameter later in this tutorial.
Example
Copy code The code is as follows:

$("button").click(function(){
$("p").hide(1000);
});

The callback parameter is the name of the function to be executed after this function completes. You'll learn more about the callback parameter later in this tutorial.

jQuery sliding function - slideDown, slideUp, slideToggle

jQuery has the following sliding functions:

Copy code The code is as follows:

$(selector).slideDown(speed,callback)
$(selector).slideUp(speed,callback)
$(selector).slideToggle(speed,callback)

The speed parameter can set these values: "slow", "fast", "normal" or milliseconds.
The callback parameter is the name of the function to be executed after this function completes. You'll learn more about the callback parameter later in this tutorial.
slideDown() instance
Copy code The code is as follows:

$(".flip").click(function(){
$(".panel").slideDown();
});

jQuery Fade function - fadeIn(), fadeOut(), fadeTo()
jQuery has the following fade function:
Copy code The code is as follows:

$(selector).fadeIn(speed,callback)

$(selector).fadeOut(speed,callback)

$(selector).fadeTo(speed,opacity,callback)


The speed parameter can set these values: "slow", "fast", "normal" or milliseconds.
The opacity parameter in the fadeTo() function specifies the fade to a given opacity.
The callback parameter is the name of the function to be executed after this function completes. You'll learn more about the callback parameter later in this tutorial.

jQuery custom animation

Syntax for creating custom animations using jQuery function:

Copy code The code is as follows:

$(selector).animate({params},[duration],[easing],[callback])

The key parameters are params. It defines the CSS properties that animate. Multiple such properties can be set simultaneously:
Copy code The code is as follows:

animate({width:"70%",opacity:0.4,marginLeft:"0.6in",fontSize:"3em"});

The second parameter is duration. It defines the time used to apply to the animation. The values ​​it sets are: "slow", "fast", "normal" or milliseconds.
Example
Copy code The code is as follows:

<script type="text/javascript">
$(document).ready(function(){
$("#start").click(function(){
$("#box").animate({height:300},"slow");
$("#box").animate({width:300},"slow");
$("#box").animate({height:100},"slow");
$("#box").animate({width:100},"slow");
});
});
</script>
函数 描述
$(selector).hide() 隐藏被选元素
$(selector).show() 显示被选元素
$(selector).toggle() 切换(在隐藏与显示之间)被选元素
$(selector).slideDown() 向下滑动(显示)被选元素
$(selector).slideUp() 向上滑动(隐藏)被选元素
$(selector).slideToggle() 对被选元素切换向上滑动和向下滑动
$(selector).fadeIn() 淡入被选元素
$(selector).fadeOut() 淡出被选元素
$(selector).fadeTo() 把被选元素淡出为给定的不透明度
$(selector).animate() 对被选元素执行自定义动画
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to hide WeChat friends without blocking or deleting them? How to hide WeChat friends without blocking or deleting them How to hide WeChat friends without blocking or deleting them? How to hide WeChat friends without blocking or deleting them Mar 13, 2024 pm 07:19 PM

How to hide WeChat friends without blocking or deleting them? How to hide WeChat friends without blocking or deleting them

Operation tutorial for switching from win11 home version to professional version_Operation tutorial for switching from win11 home version to professional version Operation tutorial for switching from win11 home version to professional version_Operation tutorial for switching from win11 home version to professional version Mar 20, 2024 pm 01:58 PM

Operation tutorial for switching from win11 home version to professional version_Operation tutorial for switching from win11 home version to professional version

How to hide works in Douyin short videos How to hide personal video works How to hide works in Douyin short videos How to hide personal video works Mar 12, 2024 pm 12:49 PM

How to hide works in Douyin short videos How to hide personal video works

How to hide Smart Island on Xiaomi Mi 14? How to hide Smart Island on Xiaomi Mi 14? Mar 18, 2024 pm 03:40 PM

How to hide Smart Island on Xiaomi Mi 14?

Detailed tutorial on hiding works on Douyin Detailed tutorial on hiding works on Douyin Mar 25, 2024 pm 03:11 PM

Detailed tutorial on hiding works on Douyin

How to deeply clean the hidden junk on your phone (completely remove junk from your phone's memory) How to deeply clean the hidden junk on your phone (completely remove junk from your phone's memory) Jun 01, 2024 am 09:29 AM

How to deeply clean the hidden junk on your phone (completely remove junk from your phone's memory)

How to use shortcut keys for switching workbooks in excel How to use shortcut keys for switching workbooks in excel Mar 20, 2024 pm 01:50 PM

How to use shortcut keys for switching workbooks in excel

Understanding full-width and half-width: a look at switching techniques Understanding full-width and half-width: a look at switching techniques Mar 25, 2024 pm 01:36 PM

Understanding full-width and half-width: a look at switching techniques

See all articles