jQuery achieves fade-in and fade-out effects

jQuery achieves fade-in and fade-out effects

Before using jQuery to complete the fade-in and fade-out effect, let's first get to know some codes:

  • fadeIn([ speed , [easing] , [fn] ]), parameters are optional
  • fadeOut([ speed , [easing] , [fn] ]), parameters are optional
  • Fade in and out switch fadeToggle([ speed , [easing] , [fn] ]), parameters can be omitted
  • Modify the transparency fadeTo([ [speed] , opacity , [easing] , [fn] ]). Note that the speed and transparency must be written here.

in

  • speed is speed
  • Easing is the transition effect
  • fn is the callback function

Then let's put the above code into the overall code to see the effect

The complete code is as follows

<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <title>Wellfancy</title>
    <style>
        div {
   margin: 10px;
   padding: 10px;
   width: 100px;
            display: none;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
 
<body>
    <button>Fade-in effect</button>
    <button>Fade out effect</button>
    <button>Fade in and out switch</button>
    <button>Modify transparency</button>
    <div>
  <img src="images/1.jpg" style="width: 280px;">
 </div>
    <script>
        $(function() {
            $("button").eq(0).click(function() {
                $("div").fadeIn(1000);
            })
            $("button").eq(1).click(function() {
                $("div").fadeOut(1000);
 
            })
            $("button").eq(2).click(function() {
                $("div").fadeToggle(1000);
 
            });
            $("button").eq(3).click(function() {
                $("div").fadeTo(1000, 0.5);
 
            });
 
        });
    </script>
</body>
 
</html>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Native js and jquery to achieve the fade-in and fade-out effect of image carousel
  • Examples of fade-in and slide-out effects implemented with jQuery
  • Simple implementation of jQuery fade-in and fade-out effect
  • jQuery implements universal version of mouse fade-in and fade-out effect
  • jQuery fade in and out, expand and shrink menu implementation code
  • Text fade-in and fade-out effect based on jQuery
  • Implementing fade-in and fade-out effect carousel based on jQuery
  • Basic practice of fade-in and fade-out special effects based on Jquery
  • jQuery news broadcast scrolling and fade-in and fade-out effect example
  • jQuery fades elements in and out to make the effect more vivid

<<:  MySQL 8.0.18 stable version released! Hash Join is here as expected

>>:  Detailed tutorial on migrating the home directory to a new partition under Ubuntu

Recommend

Solution to ONLY_FULL_GROUP_BY error in Mysql5.7 and above

Recently, during the development process, the MyS...

A brief analysis of Vue's asynchronous update of DOM

Table of contents The principle of Vue asynchrono...

Analysis of the Poor Performance Caused by Large Offset of LIMIT in MySQL Query

Preface We all know that MySQL query uses the sel...

jQuery implements clicking left and right buttons to switch pictures

This article example shares the specific code of ...

MySQL 8.0.18 installation and configuration method graphic tutorial

This article records the installation and configu...

How to automatically start RabbitMq software when centos starts

1. Create a new rabbitmq in the /etc/init.d direc...

Cross-origin image resource permissions (CORS enabled image)

The HTML specification document introduces the cr...

Vue.js application performance optimization analysis + solution

Table of contents 1. Introduction 2. Why do we ne...

How to use Baidu Map API in vue project

Table of contents 1. Register an account on Baidu...

Superficial Web Design

<br />I have always believed that Yahoo'...

css add scroll to div and hide the scroll bar

CSS adds scrolling to div and hides the scroll ba...

Docker completely deletes private library images

First, let’s take a look at the general practices...

Vue dynamic menu, dynamic route loading and refresh pitfalls

Table of contents need: Ideas: lesson: Share the ...