jQuery clicks on the love effect

jQuery clicks on the love effect

This article shares the specific code of jQuery's love effect when you click it for your reference. The specific content is as follows

Code:

<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8" />
        <title>Heart Effect</title>
        <script type="text/javascript" src="jquery-3.2.1.min.js"></script>
        <style type="text/css">
            #love
                width: 30px;
                height: 30px;
                /*border: 1px solid red;*/
                position: absolute;
            }
            
            #first {
                width: 15px;
                height: 26px;
                background-color: red;
                position: absolute;
                right: 3.2px;
                bottom: 0;
                transform: rotate(45deg);
                border-radius: 10px 10px 1px 1px;
                opacity: 1;
            }
            
            #second {
                width: 15px;
                height: 26px;
                background-color: red;
                position: absolute;
                left: 3.2px;
                bottom: 0;
                transform: rotate(-45deg);
                border-radius: 10px 10px 1px 1px;
                opacity: 1;
            }
        </style>
    </head>

    <body></body>

    <script type="text/javascript">
        function random(lower, upper) {
            return Math.floor(Math.random() * (upper - lower)) + lower;
        }
        var body = document.getElementsByTagName("body")[0];
        document.onclick = function(e) {
            var num = random(0, 19);
            // Color array var color = ["peru", "goldenrod", "yellow",
                "chartreuse", "palevioletred", "deeppink",
                "pink", "palegreen", "plum",
                "darkorange", "powderblue", "orange",
                "orange", "orchid", "red",
                "aqua", "salmon", "gold", "lawngreen"
            ]

            var divmain = document.createElement("div");
            var first = document.createElement("div");
            var second = document.createElement("div");
            // Add attributes to div divmain.setAttribute("id", "love");
            divmain.setAttribute("class", "love");
            first.setAttribute("id", "first");
            second.setAttribute("id", "second");
            // Add inner div to the outermost layer
            divmain.appendChild(first);
            divmain.appendChild(second);
            // Determine the position of div based on the mouse position //divmain.style.top = e.pageY + "px";
            //divmain.style.left = e.pageX + "px";
            divmain.style.cssText = "top:" + e.pageY + "px;left:" + e.pageX + "px";

            // Add random colors to the heart-shaped div first.style.backgroundColor = color[num];
            second.style.backgroundColor = color[num];
            body.appendChild(divmain);

            $(".love").animate({
                opacity: "0",
                top: "-=50px"
            }, 1500);

        }

        // Use timer to clear page garbage setInterval(function() {
            var div = document.getElementsByClassName("love");
            var len = div.length;
            var num;
            for(var i = len - 1; i >= 0; i--) {
                num = parseInt(div[i].style.opacity);
                if(num <= 0) {
                    div[i].remove();
                }
            }

        }, 3500);
    </script>

</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:
  • Use snowfall.jquery.js to achieve the effect of flying hearts all over the screen
  • jquery+html5 romantic love confession animation code sharing
  • Love tree confession animation made with jQuery and HTML5

<<:  VMware vSAN Getting Started Summary

>>:  MySQL database optimization: detailed explanation of table and database sharding operations

Recommend

JavaScript implementation of the Game of Life

Table of contents Concept Introduction Logical ru...

htm beginner notes (must read for beginners)

1. What is HTML HTML (HyperText Markup Language):...

Access the MySQL database by entering the DOS window through cmd under Windows

1. Press win + R and type cmd to enter the DOS wi...

Sample code for modifying the input prompt text style in html

On many websites, we have seen the input box disp...

Install redis and MySQL on CentOS

1|0MySQL (MariaDB) 1|11. Description MariaDB data...

Simple example of adding and removing HTML nodes

<br />Simple example of adding and removing ...

30 free high-quality English ribbon fonts

30 free high-quality English ribbon fonts for down...

Vue achieves seamless carousel effect

This article shares the specific code of Vue to a...

Detailed explanation of MySQL combined index and leftmost matching principle

Preface I have seen many articles about the leftm...

Native JS implements a very good-looking counter

Today I will share with you a good-looking counte...

Steps to use autoconf to generate Makefile and compile the project

Preface Under Linux, compilation and linking requ...

Eight ways to implement communication in Vue

Table of contents 1. Component Communication 1. P...

About Zabbix forget admin login password reset password

The problem of resetting the password for Zabbix ...