Home Web Front-end JS Tutorial js and html5 realize the generation of automatic arrangement dialog box

js and html5 realize the generation of automatic arrangement dialog box

Jan 26, 2018 am 09:19 AM
html5 javascript dialog box

This article mainly introduces an example of the automatic arrangement dialog box generated by js+html5. Multiple dialog boxes pop up and can be arranged automatically. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

Recently written using js and html5, multiple dialog boxes pop up, and they can be automatically arranged. When the screen is full, it will automatically start from the beginning. Without further ado, just look at the picture:
How to use it It is still very convenient. If you are interested, the code is at the back

The first is the Html page


1

2

3

4

5

6

7

8

9

10

11

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <title>Title</title>

</head>

<body style="width: 100vw;height: 100vh;padding: 0;margin: 0">

<input type="button" value="生成p" onclick="creatDialog()" style="position: absolute;z-index: 200;"/>

<script src="index.js"></script>

</body>

</html>

Copy after login

Then js


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

function creatDialog() {

  // 获取屏幕的宽度和高度

  var wid=document.body.clientWidth;

  var hei=document.body.clientHeight;

  

  //根据已有dialog计算下一个dialog位置

  var obj=document.getElementsByClassName("dialog");

  //5和10为间距

  var top=5;

  var left=10;

  

  if(obj.length!=0){

    //不是第一次生成

    var h=parseInt(hei/(274+5));//求出总行数

    var w=parseInt(wid/(300+10));//求出总列数

    var n=parseInt(obj.length/h);//位于第n+1列

    if(n+1<=w){

      var m=obj.length%h//位于第m+1行

      top=(274+5)*m+5;

      left=(300+10)*n+10;

    }else {

      //屏幕满了移除所有对象,从新开始

      removeDialog();

       top=5;

       left=10;

    }

  

  }

//生成dialog

  var dialog=document.createElement(&#39;p&#39;);

  dialog.className="dialog";

  dialog.id="dialog"+obj.length;

  dialog.style.position="absolute";

  dialog.style.marginLeft=left+"px";

  dialog.style.marginTop=top+"px";

  dialog.style.width="300px";

  dialog.style.height="274px";

  dialog.style.border="solid 1px";

  dialog.style.backgroundColor="#FF0000";

  document.body.appendChild(dialog);

}

  

function removeDialog() {

  var obj=document.getElementsByClassName("dialog");

  var num=obj.length;

  for(var i=0;i<num;i++){

    document.body.removeChild(document.getElementById("dialog"+i));

  }

}

Copy after login

Related recommendations:

WeChat applet uses modal component to pop up dialog box example sharing

js tutorial for making a simple dialog box

10 recommended courses on dialog boxes

The above is the detailed content of js and html5 realize the generation of automatic arrangement dialog box. For more information, please follow other related articles on the PHP Chinese website!

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 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

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)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

See all articles