search
HomeWeb Front-endJS TutorialWhat special effects can jQuery achieve? Use of jQuery special effects (code example)

The content of this article is to introduce what kind of special effects jQuery can achieve? Use of jQuery special effects (code example). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. [Recommended related video tutorials: jQuery Tutorial]

1. jQuery Effect--Hide and Show

Use the hide() and show() methods to hide and show HTML elements.

Example:

nbsp;html>


<meta>
<title>My Test JQuery</title>
    <script></script>
    <script>    
        $(function(){
            $("#btnHide").click(function(){
                $("#myDiv1").hide();
                //语法格式:$(selector).hide(speed,callback);
                //可选参数1:speed 参数规定隐藏/显示的速度,可以取值:"slow"、"fast" 或毫秒。
                //可选参数2:callback 参数是隐藏或显示完成后所执行的函数名称。

                // callback的使用如下,即第2个参数是一个函数,jQuery效果执行完会执行该函数。
                // $("#myDiv1").hide(3000,function(){
                //      alert("myDiv1隐藏了");
                // });
            });
            
            $("#btnShow").click(function(){
                $("#myDiv1").show();
                //语法格式:$(selector).show(speed,callback); 
                //可选参数1:speed 参数规定隐藏/显示的速度,可以取值:"slow"、"fast" 或毫秒。
                //可选参数2:callback 参数是隐藏或显示完成后所执行的函数名称。
            });
        });
    </script>


    <button>隐藏</button>
    <button>显示</button>
    <div></div>

  

2. jQuery effect - fade in and fade out

 (1) The fadeIn() method is used to fade in hidden elements.

 (2) The fadeOut() method is used to fade out visible elements.

 (3) The fadeToggle() method can switch between the fadeIn() and fadeOut() methods. If the element is already faded out, add a fade in effect. If the element is already faded in, add a fade out effect.

 (4) The fadeTo() method allows a gradient to a given opacity (value between 0 and 1).

Example:

nbsp;html>


<meta>
<title>My Test JQuery</title>
    <script></script>
    <script>    
        $(function(){
            $("#btnfadeIn").click(function(){
                $("#myDiv1").fadeIn();
                //语法格式:$(selector).fadeIn(speed,callback);
                //可选参数1:speed 参数规定效果的时长。它可以取值:"slow"、"fast" 或毫秒。
                //可选参数2:callback 参数是该效果完成后所执行的函数名称。
            });
            
            $("#btnfadeOut").click(function(){
                $("#myDiv1").fadeOut();
                //语法格式:$(selector).fadeOut(speed,callback);
                //可选参数1:speed 参数规定效果的时长。它可以取值:"slow"、"fast" 或毫秒。
                //可选参数2:callback 参数是该效果完成后所执行的函数名称。
            });

            $("#btnfadeToggle").click(function(){
                $("#myDiv1").fadeToggle();
                //语法格式:$(selector).fadeToggle(speed,callback);
                //可选参数1:speed 参数规定效果的时长。它可以取值:"slow"、"fast" 或毫秒。
                //可选参数2:callback 参数是该效果完成后所执行的函数名称。
            });

            $("#btnfadeTo").click(function(){
                $("#myDiv1").fadeTo("slow",0.35); 
                //语法格式:$(selector).fadeTo(speed,opacity,callback);
                //第一个参数是必须的:传入的值可以是"slow"、"fast" 、毫秒;
                //第二个参数是必须的:传入值是透明度,取值在0-1之间
                //第三个参数是可选的:callback 参数是该效果完成后所执行的函数名称。
            });
        });
    </script>


    <button>fadeIn</button>
    <button>fadeOut</button>
    <button>fadeToggle</button>
    <button>fadeTo</button>
    <div></div>

3. jQuery effect-sliding

 (1) slideDown() method is used for downward Sliding element.

 (2) The slideUp() method is used to slide the element up.

 (3) The slideToggle() method can switch between the slideDown() and slideUp() methods. If the elements are already slid down, slide them up. If the elements are already slid up, slide them down.

Example:

nbsp;html>


<meta>
<title>My Test JQuery</title>
    <script></script>
    <script>    
        $(function(){
            $("#btnslideDown").click(function(){
                $("#myDiv1").slideDown();
                //语法格式:$(selector).slideDown(speed,callback);
                //可选参数1:speed 参数规定效果的时长。它可以取值:"slow"、"fast" 或毫秒。
                //可选参数2:callback 参数是滑动完成后所执行的函数名称。
            });
            
            $("#btnslideUp").click(function(){
                $("#myDiv1").slideUp();
                //语法格式:$(selector).slideUp(speed,callback);;
                //可选参数1:speed 参数规定效果的时长。它可以取值:"slow"、"fast" 或毫秒。
                //可选参数2:callback 参数是滑动完成后所执行的函数名称。

            });

            $("#btnslideToggle").click(function(){
                $("#myDiv1").slideToggle();
                //语法格式:$(selector).slideToggle(speed,callback);;
                //可选参数1:speed 参数规定效果的时长。它可以取值:"slow"、"fast" 或毫秒。
                //可选参数2:callback 参数是滑动完成后所执行的函数名称。
            });

        });
    </script>


    <button>slideDown</button>
    <button>slideUp</button>
    <button>slideToggle</button>
    <div></div>

4. jQuery Effect - Animation

The animate() method is used to create custom animations.

Example:

nbsp;html>


<meta>
<title>My Test JQuery</title>
    <script></script>
    <script>    
        $(function(){
            $("#btn_animate").click(function(){
                $("#myDiv1").animate({left:&#39;250px&#39;});
                //语法格式:$(selector).animate({params},speed,callback);
                //第一个参数是必须的:值是定义形成动画的 CSS 属性
                //第二个参数是可选的:传入的值是"slow"、"fast" 、毫秒
                //第三个参数是可选的:callback 参数是该效果完成后所执行的函数名称
                 
                //第一个参数的css属性也可以使用相对值,像下面这样
                //$("#myDiv1").animate({left:&#39;250px&#39;,height:&#39;+=10px&#39;,width:&#39;+=10px&#39;});
            });
            
        });
    </script>


    <button>animate</button>
    <div></div>

5. jQuery -- Stop animation

The stop() method is used to stop animations or effects before they are completed.

The stop() method applies to all jQuery effect functions, including sliding, fading, and custom animations.

Example:

nbsp;html>


<meta>
<title>My Test JQuery</title>
    <script></script>
    <script>    
        $(function(){
            $("#btn_animate").click(function(){
                $("#myDiv1").animate({left:&#39;250px&#39;},5000);
            });

            $("#btn_stop").click(function(){
                $("#myDiv1").stop();
                //语法格式:$(selector).stop(stopAll,goToEnd);
                //可选参数1:规定是否应该清除动画队列。默认是 false,即仅停止活动的动画,允许任何排入队列的动画向后执行。
                //可选参数2:规定是否立即完成当前动画。默认是 false。
            });
            
        });
    </script>


    <button>animate</button>
    <button>Stop</button>
    <div></div>

6, jQuery -- Chain Programming

Chain Programming :Run multiple jQuery commands on the same element, one right after the other. This way, the browser doesn't have to look for the same element multiple times. To link an action, you simply append the action to the previous action.

Example:

nbsp;html>


<meta>
<title>My Test JQuery</title>
    <script></script>
    <script>    
        $(function(){  
            $("#btnLink").click(function(){
                $("#myDiv1").css("background-color","yellow").slideUp(2000).slideDown(2000);
            });
        });
    </script>


    <button>链式编程</button>
    <div></div>

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning. For more jQuery special effects, it is recommended to visit: js special effects collection!

The above is the detailed content of What special effects can jQuery achieve? Use of jQuery special effects (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:博客园. If there is any infringement, please contact admin@php.cn delete
From Websites to Apps: The Diverse Applications of JavaScriptFrom Websites to Apps: The Diverse Applications of JavaScriptApr 22, 2025 am 12:02 AM

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python vs. JavaScript: Use Cases and Applications ComparedPython vs. JavaScript: Use Cases and Applications ComparedApr 21, 2025 am 12:01 AM

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

The Role of C/C   in JavaScript Interpreters and CompilersThe Role of C/C in JavaScript Interpreters and CompilersApr 20, 2025 am 12:01 AM

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript in Action: Real-World Examples and ProjectsJavaScript in Action: Real-World Examples and ProjectsApr 19, 2025 am 12:13 AM

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool