Home > Web Front-end > JS Tutorial > How to change mouse pointer style with JavaScript

How to change mouse pointer style with JavaScript

青灯夜游
Release: 2023-01-07 11:44:24
Original
15382 people have browsed it

In JavaScript, you can change the mouse pointer style through the cursor attribute of the style object, which defines the cursor shape used when the mouse pointer is placed within the boundary of an element; the syntax format is "element object.style. cursor= "pointer style value"".

How to change mouse pointer style with JavaScript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

How to change the mouse pointer style in JavaScript

In js we can use the cursor attribute of the style object Set the style of the mouse pointer, for example

 var body = document.querySelector("body")
	body.style.cursor= "move"
Copy after login

The above code realizes that after the page is opened, the mouse pointer is replaced with a cross style. In fact, there are many styles, as shown in the figure below
How to change mouse pointer style with JavaScript
We can also replace the pointer with a custom image through the cursor attribute. The method is as follows

	obox1.onmousemove = function(){
		this.style.cursor = 'url(../favicon.ico),auto';
	}
Copy after login

It should be noted that the image in the url only supports .cur and .ico Pictures in format. Here we recommend a website that generates ico format online. Click here to jump.

The auto after the url can be set by yourself. When the path of the replaced image is wrong or the format is not found, the style that the mouse pointer will use.

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of How to change mouse pointer style with JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template