Javascript to achieve the effect of closing advertisements

Javascript to achieve the effect of closing advertisements

Here is a case study on how to close ads using Javascript for your reference. The details are as follows:

I am still learning the big front end. Please forgive me if there are any irregular or incorrect codes and ideas. Thank you for your advice.

We can often see annoying small advertisements on web pages, and there is usually a specific position and icon next to the advertisement to close the advertisement. The following JS code is used to simply implement

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    *{
      padding: 0;
      margin: 0;
      border: 0;
    }
    .gg{
      width: 100%;
      height: 300px;
      background-image: url("../images/JD.png");
    }
    .img{
      width: 20px;
      height: 20px;
      float: right;
    }
  </style>
</head>
<body>
<div class="gg">
  <img class="img" src="../images/2.jpg" title="Close">
</div>
<script>
  var gg = document.querySelector('.gg')
  var mg = document.querySelector('img')
  mg.onclick = function () {
    gg.style.display = 'none'
  }
</script>
</body>
</html>

Code Explanation

The principle here is very simple. I put an annoying advertising picture at the bottom of the div, and then put a small icon representing close on it, and placed it in the upper right corner of the small advertisement. Then I get the event, and when it is onclick, the function is triggered. The content of the function is to hide this large div box directly and not display it, thus achieving the purpose of closing the advertisement.

Demonstration effect

Note the upper right corner

After clicking the set location

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:
  • JS realizes closing small advertisement special effects
  • JS implements the code for closing couplet advertising effect
  • JS lower right corner advertising window code (can be shrunk, expanded and closed)
  • js implements the floating ad bar code that can be closed at the top of the website
  • JS implements the left ad code that can be clicked to expand and close
  • JavaScript to achieve advertising closing and display effects example
  • js to achieve the following mouse movement and close the picture advertising example
  • Javascript implements web page floating ad code with close button
  • js pop-up ad code when IE is closed to prevent blocking

<<:  How to change mysql password under Centos

>>:  Problems and solutions for MYSQL5.7.17 connection failure under MAC

Recommend

MySQL 8.0.14 installation and configuration method graphic tutorial

This article records the installation and configu...

Detailed tutorial on deploying Apollo custom environment with docker-compose

Table of contents What is the Apollo Configuratio...

9 ways to show and hide CSS elements

In web page production, displaying and hiding ele...

Basic principles for compiling a website homepage

1. The organizational structure of the hypertext d...

A brief discussion on the whole process of Vue's first rendering

Table of contents 1. Vue initialization vue entry...

Batch replace part of the data of a field in Mysql (recommended)

Batch replace part of the data of a field in MYSQ...

Unicode signature BOM detailed description

Unicode Signature BOM - What is the BOM? BOM is th...

A record of the pitfalls of the WeChat applet component life cycle

The component lifecycle is usually where our busi...

Docker installs Redis and introduces the visual client for operation

1 Introduction Redis is a high-performance NoSQL ...

SQL Practice Exercise: Online Mall Database Product Category Data Operation

Online shopping mall database-product category da...

Several common methods of CSS equal height layout

Equal height layout Refers to the layout of child...

Tips for adding favicon to a website: a small icon in front of the URL

The so-called favicon, which is the abbreviation o...

js implements clock component based on canvas

Canvas has always been an indispensable tag eleme...