A JavaScript fondly effects

  • 2020-03-30 02:56:37
  • OfStack

There is a JavaScript special effect, the effect is as follows:

Not only can appear the effect of the graph below, still can make this graph follow the mouse to rotate, this inside is just a simple without embellish small example, can make courtship based on this example, more fun. Bored coquetty guys, can you send your little girl a web page like this? To force.
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201405/201405091026534.gif? 201449102712 ">
Paste code:
<!DOCTYPE html> 
<meta charset="UTF-8"> 
<title>Insert title here</title> 
<style type="text/css"> 
border:1px red solid; 
margin : 0px auto; 
<script type="text/javascript"> 
//Why use onload, because when I initialize the div of the clock in javascript code, the debug page is not implemented
//It turned out that the HTML code was parsed from front to back. When the JavaScript code is parsed first, go to the body
//When you add a child node, you cannot find the body that has not yet been resolved. So we should parse the body first. There are two ways to do it, one is down
//, or you can add the onload method to the body tag.
//Define an array of divs to store 12 divs
//Because of the 12 divs, let's first determine the dot and radius so that we can calculate the div position
var divs=[]; 
var loveBaby=[" I "," love "," you "," ! "," treasure "," Mr. "," you "," love "," I "," ? "," mian "," mian "] 
var CX=300; 
var CY=300;//-- does the position coordinate in the web page have units?
var R=150; 
var divCenterNode;//The position of the center point is controlled and global variables are set
//Define an initialized function
function init(){ 
//Create a div with a center point
divCenterNode.innerHTML=" Tingting, marry me! "; 
//Create 12 divs to make a forbidden clock and place it in the body
for(var x=1;x<=12;x++){ 
//Create a div
var divNode=document.createElement("div"); 
//The body object doesn't need to be fetched like any other object, the js library is already encapsulated.
//Reposition the div element each time startClock() is started

//The offset of div
var offset=0;//Degree offset
//Define a separate function for positioning and rotation of position
function startClock(){ 
for(var x=1;x<=12;x++){ 
var div = divs[x-1]; 
//The degree of each number
var dushu=30*x+offset; 
//Angle * math.pi /180 = radians
var divLeft = CX+R*Math.sin(dushu*Math.PI/180); 
var divTop = CY-R*Math.cos(dushu*Math.PI/180); 
//Call this function back at regular intervals
//Evaluates an expression after specifying a value for milliseconds. The first parameter is the expression, and the second parameter is the time
setTimeout(startClock,80);//Method of the window object
//Define the clock to move to different positions with the mouse
function clockMove(event){ 
CX=event.clientX;//The x position of the mouse
CY=event.clientY;//The y position of the mouse

<body onmousemove="clockMove(event)"> 
 A, 12 The Numbers are displayed in a circle  
1 create 12 a DIV , respectively  1--12 
2 to 12 a DIV Position, circle.  
</body > 

The idea was to make a clock display that would turn and run. So the naming in the code is related to the clock, so I don't have to worry about that, dear. As a beginner, javascript is very powerful.

Related articles: