Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use javascript to be shy and silently close one by one

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use javascript to be shy and silently close one by one". Friends who are interested might as well take a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to use javascript to be shy and silently close one by one"!

First of all, show the effect of the word "Tian"

The thought of realization is mainly divided into several parts.

Randomly generate color values

Var getRandomColor = function () {return'#'+ (function (color) {return (color + = '0123456789abcdef' [Math.floor (Math.random () * 16)]) & & (color.length = = 6)? Color: arguments.callee (color);}) (');}

Create a span tag and insert it into the div.

CreSpan function, n refers to the current number, mpid refers to the parent container div,mleft refers to the left value of the current span, and mtop refers to the top value of the current span

Function creSpan {var mSpan = document.createElement ("span"); var pId = mpId [0]; pId.appendChild (mSpan); with (mSpan.style) {left = mleft+ "px"; top = mtop+ "px"; background = getRandomColor ();}}

Generate the word "Tian"

Create a two-dimensional array to hold objects for each creSpan. The distance from the left to the top of the default initial value of myleft=100,mtop=50.

Draw the word "field" and use a double cycle to generate it.

Var myleft = 100; var mytop = 50; var arr = new Array (); var test = $("# test"); for (var

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report