Get the App
SLTechnology News&Howtos  ›  Development  › 

How to generate Random div by Click in js

Shulou Source: shulou.com Published: 2022-06-03 09:47:30 11月15日 Update

This article mainly introduces js how to click to generate random div, the article is very detailed, has a certain reference value, interested friends must read it!

Description:

Mouse click on the page, where you click to create a p, width and height 50, random color, p in the middle of the mouse click

Effect:

Achieve:

Js:

Var Method= (function () {return {EVENT_ID: "event_id", loadImage:function (arr) {var img=new Image (); img.arr=arr; img.list= []; img.num=0) / / if the event listening under the DOM object is not deleted, it will reside in the heap / / once the necessary conditions for the event are triggered, the event function img.addEventListener ("load", this.loadHandler); img.self=this; img.src=arr [img.num];}, loadHandler:function (e) {this.list.push (this.cloneNode (false)); this.num++ will continue to be executed. If (this.num > this.arr.length-1) {this.removeEventListener ("load", this.self.loadHandler); var evt=new Event (Method.EVENT_ID); evt.list=this.list; document.dispatchEvent (evt); return;} this.src=this.arr [this.num];}, $c:function (type,parent,style) {var elem=document.createElement (type) If (parent) parent.appendChild (elem); for (var key in style) {elem.style [key] = style [key];} return elem;}, pColor: function () {var col= "#"; / / the format for in which the first bit of this string is # color (var iTuno

Tags: Format color event generation content character string article binary mouse value location interest function reason object buddy effect more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information MySQL Docker Apple