


js method to realize text moving according to mouse movement_javascript skills
The example in this article describes how js implements text movement following mouse movement. Share it with everyone for your reference. The specific analysis is as follows:
This is a very simple mouse feature code. When you move the mouse on a web page, a string of text will follow the mouse movement
<script><br> var x,y<br> var step=18 //This is the interval between two adjacent words <br> var flag=0<br> var message="Script House www.jb51.net welcomes you!" //Put the text that needs to be displayed here<br> message=message.split("") //Split the string into an array<br> var xpos=new Array() //Create an array to record the x coordinate of each position<br> for (i=0;i<=message.length-1;i) { //Assign an initial value to each element<br /> xpos[i]=-50<br /> }<br /> var ypos=new Array() //Create an array to record the y coordinate of each position<br /> for (i=0;i<=message.length-1;i) {<br /> ypos[i]=-200<br /> }<br /> function movehandler(e){ //Handle mouse move events<br /> x = (document.layers) ? e.pageX : document.body.scrollLeft event.clientX //According to different browsers, record the horizontal position of the mouse <br /> y = (document.layers) ? e.pageY : document.body.scrollTop event.clientY //Record the vertical position of the mouse<br /> flag=1 //The mouse position has changed and needs to be recalculated <br /> }<br /> function makesnake() {<br /> if (flag==1 && document.all) { //If it is IE<br /> for (i=message.length-1; i>=1; i--) { //Process coordinate queue<br> xpos[i]=xpos[i-1] step //Move each coordinate data forward one space and add character spacing <br> ypos[i]=ypos[i-1]<br> }<br> xpos[0]=x step //Write new data into the end of the coordinate data queue<br> ypos[0]=y<br> for (i=0; i<message.length-1; i ) {<br /> var thisspan = eval("span" (i) ".style")// Generate the current operation object spanx.style<br /> thisspan.posLeft=xpos[i]<br /> thisspan.posTop=ypos[i]<br /> }<br /> }<br /> else if (flag==1 && document.layers) { //If it is NS<br /> for (i=message.length-1; i>=1; i--) { //Process coordinate queue<br> xpos[i]=xpos[i-1] step //Move each coordinate data forward one space and add character spacing <br> ypos[i]=ypos[i-1]<br> }<br> xpos[0]=x step //Write new data into the end of the coordinate data queue<br> ypos[0]=y<br> for (i=0; i<message.length-1; i ) { //Change the coordinates of the layer where each word is located according to the data in the array <br /> var thisspan = eval("document.span" i) //Generate the current operation object document.spanx<br /> thisspan.left=xpos[i]<br /> thisspan.top=ypos[i]<br /> }<br /> }<br /> var timer=setTimeout("makesnake()",30) //After 30 milliseconds, adjust the position of each character according to the situation again<br /> }<br /> </script>
<script><br> <!-- Beginning of JavaScript -<br /> //Generate a span as a container for each word here <br /> for (i=0;i<=message.length-1;i) {<br /> document.write("<span id='span" i "' class='spanstyle'>")<br> document.write(message[i])<br> document.write("</span>")<br> }<br> //Specify the processing process of mouse movement events<br> if (document.layers){<br> document.captureEvents(Event.MOUSEMOVE);<br> }<br> document.onmousemove = movehandler;<br> // - End of JavaScript - --><br> </script>
Isn’t this effect cool?
I hope this article will be helpful to everyone’s JavaScript programming design.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



First, draw a circle in PPT, then insert a text box and enter text content. Finally, set the fill and outline of the text box to None to complete the production of circular pictures and text.

Tomato Novel is a very popular novel reading software. We often have new novels and comics to read in Tomato Novel. Every novel and comic is very interesting. Many friends also want to write novels. Earn pocket money and edit the content of the novel you want to write into text. So how do we write the novel in it? My friends don’t know, so let’s go to this site together. Let’s take some time to look at an introduction to how to write a novel. Share the Tomato novel tutorial on how to write a novel. 1. First open the Tomato free novel app on your mobile phone and click on Personal Center - Writer Center. 2. Jump to the Tomato Writer Assistant page - click on Create a new book at the end of the novel.

Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

According to news from this website on March 31, HP recently launched a Professor1 three-mode Bluetooth mouse on JD.com, available in black and white milk tea colors, with an initial price of 99 yuan, and a deposit of 10 yuan is required. According to reports, this mouse weighs 106 grams, adopts ergonomic design, measures 127.02x79.59x51.15mm, has seven optional 4000DPI levels, is equipped with a Blue Shadow RAW3220 sensor, and uses a 650 mAh battery. It is said that it can be used on a single charge. 2 months. The mouse parameter information attached to this site is as follows:

According to news from this site on July 12, Razer today announced the launch of the Razer|Pokémon Gengar wireless mouse and mouse pad. The single product prices are 1,299 yuan and 299 yuan respectively, and the package price including the two products is 1,549 yuan. This is not the first time that Razer has launched Gengar co-branded peripheral products. In 2023, Razer launched the Gengar-style Yamata Orochi V2 gaming mouse. The two new products launched this time all use a dark purple background similar to the appearance of the Ghost, Ghost, and Gengar families. They are printed with the outlines of these three Pokémon and Poké Balls, with the character Gengar in the middle. A large, colorful image of a classic ghost-type Pokémon. This site found that the Razer|Pokémon Gengar wireless mouse is based on the previously released Viper V3 Professional Edition. Its overall weight is 55g and equipped with Razer’s second-generation FOC

According to news from this site on August 12, VGN launched the co-branded "Elden Ring" keyboard and mouse series on August 6, including keyboards, mice and mouse pads, designed with a customized theme of Lani/Faded One. The current series of products It has been put on JD.com, priced from 99 yuan. The co-branded new product information attached to this site is as follows: VGN丨Elden Law Ring S99PRO Keyboard This keyboard uses a pure aluminum alloy shell, supplemented by a five-layer silencer structure, uses a GASKET leaf spring structure, has a single-key slotted PCB, and the original height PBT material Keycaps, aluminum alloy personalized backplane; supports three-mode connection and SMARTSPEEDX low-latency technology; connected to VHUB, it can manage multiple devices in one stop, starting at 549 yuan. VGN丨Elden French Ring F1PROMAX wireless mouse the mouse

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

In today's society, mobile phones have become an indispensable part of our lives. As an important tool for our daily communication, work, and life, WeChat is often used. However, it may be necessary to separate two WeChat accounts when handling different transactions, which requires the mobile phone to support logging in to two WeChat accounts at the same time. As a well-known domestic brand, Huawei mobile phones are used by many people. So what is the method to open two WeChat accounts on Huawei mobile phones? Let’s reveal the secret of this method. First of all, you need to use two WeChat accounts at the same time on your Huawei mobile phone. The easiest way is to
