Событие onmouseover

The content structure of a web page is coded in HTML (or XHTML), and the way in which the information is displayed is defined by Cascading Style Sheets (CSS). Some techniques for coding CSS make it possible to add animation and dynamic display to a web page so that it is not necessary to use JavaScript.

CSS animations have the advantage of being supported by all modern browsers even when a user has turned off JavaScript for security reasons or to avoid some types of advertisements. The XHTML and CSS techniques illustrated here meet all W3C validation standards and work for Internet Explorer, FireFox, Safari, Opera, and Google Chrome browsers. The description of the code is explained below.

Example of a mouseover with a text paragraph.

English grammar can be described using a formal description Formal Description
A Formal Description is like a mathematical formula that when applied to words produces a correctly formed sentence structure. The expression

means that you can create a noun phrase by first writing the article «the» and then writing a specific proper noun.

Example: «the Grand Canyon».

Читайте также:  If statement in one line php

that describes valid sequences of linguistic components.

Example of a mouseover with an image and a caption.

Female Body Mass Index

The Body Mass Index
Body Mass Index for Females is the most widely used diagnostic tool to identify weight problems within a population. The values of the BMI can usually be used to classify whether individuals are underweight, overweight or obese.

Example of a mouseover with drop-down list of links

Example of a mouseover to change an image.

Explanation of the coding techniques

In general, these techniques hide the pop-up text by placing it outside the display area, but restore it to a visible position when the mouse hovers over the designated zone.

Mouseover with a text paragraph
When the pop-up text is too long, the width of the pop-up text may be specified in the style of the second level span. A title in the first level span displays additional information on mouseover

This is a line with a Hot Zone Text Pop-up Text in the middle.

span.dropt span.dropt:hover span.dropt span span.dropt:hover span span.dropt span span.dropt:hover span

Mouseover with an image and a caption
An image can also be displayed using the same dropt class.

This is a line with a Hot Zone Text
Caption in the middle.

Hot Zone Text  
Caption

Mouseover with drop-down list of links
A drop-down list of links can be generated from nested unordered lists using the dropv class.

In order to position the drop-down list under the link, it is necessary to have the link at the beginning of a line, or to code the dropv class within a column of a table, which then can be positioned as needed.
NOTE: If the list is to drop down over a flash object, it is necessary to code the flash object with wmode=»opaque» or wmode=»transparent», otherwise the drop-down list will be behind the object.

.dropv, .dropv ul .dropv a .dropv li /* all list items */ .dropv li ul /* second-level lists */ .dropv li:hover ul /* nest list under hovered list items */ .dropv li ul li a .dropv li ul li a:hover

Mouseover to change an image.
The effect of swapping an image on mouseover may be achieved by overlapping two pictures and hiding the top one when the cursor hovers over the area. The whole span may be encompassed with an tag if a page link is needed. Since the span can be active over the entire horizontal area of the screen, it is a good idea to code the span within a table to restrict the area that activates the rollover of the image.

span.imgswap span.imgswap:hover img

Источник

Событие onmouseover

Событие onmouseover срабатывает, когда курсор мыши наводится на элемент, к которому добавлен атрибут onmouseover . Это один из самых популярных атрибутов, применяемый для создания различных эффектов с изображениями и другими объектами веб-страницы. Обычно работает в связке с событием onmouseout .

Синтаксис

Значения

Значение по умолчанию

Применяется к тегам

Пример

      

 

В данном примере при наведении курсора на изображение оно заменяется на другое, что создает эффект превращения черно-белой картинки в цветную (рис. 1).

Рис. 1

Рис. 1. Использование события onmouseover

Браузеры

Internet Explorer до версии 7.0 содержит ошибку при работе с изображениями, события onmouseover и onmouseout для тега не обрабатываются.

Не выкладывайте свой код напрямую в комментариях, он отображается некорректно. Воспользуйтесь сервисом cssdeck.com или jsfiddle.net, сохраните код и в комментариях дайте на него ссылку. Так и результат сразу увидят.

Типы тегов

HTML5

Блочные элементы

Строчные элементы

Универсальные элементы

Нестандартные теги

Осуждаемые теги

Видео

Документ

Звук

Изображения

Объекты

Скрипты

Списки

Ссылки

Таблицы

Текст

Форматирование

Формы

Фреймы

Источник

Element: mouseover event

The mouseover event is fired at an Element when a pointing device (such as a mouse or trackpad) is used to move the cursor onto the element or one of its child elements.

Syntax

Use the event name in methods like addEventListener() , or set an event handler property.

addEventListener("mouseover", (event) => >); onmouseover = (event) => >; 

Event type

Event properties

This interface also inherits properties of its parents, UIEvent and Event . MouseEvent.altKey Read only Returns true if the alt key was down when the mouse event was fired. MouseEvent.button Read only The button number that was pressed (if applicable) when the mouse event was fired. MouseEvent.buttons Read only The buttons being pressed (if any) when the mouse event was fired. MouseEvent.clientX Read only The X coordinate of the mouse pointer in local (DOM content) coordinates. MouseEvent.clientY Read only The Y coordinate of the mouse pointer in local (DOM content) coordinates. MouseEvent.ctrlKey Read only Returns true if the control key was down when the mouse event was fired. MouseEvent.layerX Non-standard Read only Returns the horizontal coordinate of the event relative to the current layer. MouseEvent.layerY Non-standard Read only Returns the vertical coordinate of the event relative to the current layer. MouseEvent.metaKey Read only Returns true if the meta key was down when the mouse event was fired. MouseEvent.movementX Read only The X coordinate of the mouse pointer relative to the position of the last mousemove event. MouseEvent.movementY Read only The Y coordinate of the mouse pointer relative to the position of the last mousemove event. MouseEvent.offsetX Read only The X coordinate of the mouse pointer relative to the position of the padding edge of the target node. MouseEvent.offsetY Read only The Y coordinate of the mouse pointer relative to the position of the padding edge of the target node. MouseEvent.pageX Read only The X coordinate of the mouse pointer relative to the whole document. MouseEvent.pageY Read only The Y coordinate of the mouse pointer relative to the whole document. MouseEvent.relatedTarget Read only The secondary target for the event, if there is one. MouseEvent.screenX Read only The X coordinate of the mouse pointer in global (screen) coordinates. MouseEvent.screenY Read only The Y coordinate of the mouse pointer in global (screen) coordinates. MouseEvent.shiftKey Read only Returns true if the shift key was down when the mouse event was fired. MouseEvent.mozInputSource Non-standard Read only The type of device that generated the event (one of the MOZ_SOURCE_* constants). This lets you, for example, determine whether a mouse event was generated by an actual mouse or by a touch event (which might affect the degree of accuracy with which you interpret the coordinates associated with the event). MouseEvent.webkitForce Non-standard Read only The amount of pressure applied when clicking. MouseEvent.x Read only Alias for MouseEvent.clientX . MouseEvent.y Read only Alias for MouseEvent.clientY .

Examples

HTML

ul id="test"> li>item 1li> li>item 2li> li>item 3li> ul> 

JavaScript

const test = document.getElementById("test"); // This handler will be executed only once when the cursor // moves over the unordered list test.addEventListener( "mouseenter", (event) =>  // highlight the mouseenter target event.target.style.color = "purple"; // reset the color after a short delay setTimeout(() =>  event.target.style.color = ""; >, 500); >, false, ); // This handler will be executed every time the cursor // is moved over a different list item test.addEventListener( "mouseover", (event) =>  // highlight the mouseover target event.target.style.color = "orange"; // reset the color after a short delay setTimeout(() =>  event.target.style.color = ""; >, 500); >, false, ); 

Result

Specifications

Источник

HTML onmouseover Event Attribute

Execute a JavaScript when moving the mouse pointer over an image:

Definition and Usage

The onmouseover attribute fires when the mouse pointer moves over an element.

Tip: The onmouseover attribute is often used together with the onmouseout attribute.

Browser Support

Syntax

Attribute Values

Technical Details

Unlock Full Access 50% off

COLOR PICKER

colorpicker

Join our Bootcamp!

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

Thank You For Helping Us!

Your message has been sent to W3Schools.

Top Tutorials
Top References
Top Examples
Get Certified

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Источник

onmouseover (HTML element)

The onmouseover attribute is one of the most commonly used event attributes. It captures the moment that a cursor crosses the boundary of an element, moving from outside to inside the element to which the attribute is applied. It differs from the onmousemove attribute, which is used to detect movement within the element’s boundaries. Once the cursor is positioned over the element, the onmouseover event remains active until the cursor is moved beyond the element’s boundaries—an event that the onmouseout attribute would capture.

The onmouseover attribute is mostly used to render visual effects such as image swapping or color changes, and has been used in this way for almost as long as JavaScript has been around.

Note that this event attribute cannot be applied to the following elements:

Example

The example below shows a simple
image swap technique, whereby mousing over the image causes the image to
change to one that reveals a location on a map:

 
onmouseover="this.src='map_location_revealed.gif';" onmouseout="this.src='map.gif';"/>Figures for February’s racing.

Value

This attribute has no fixed value. It’s up to the author to decide on the scripting that’s included here, be that a call to one or more defined functions, or a simple alert() statement.

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.0 1.5 2.0 1.3 2.0 3.0 9.2 9.5
Full Full Full Full Full Full Full Full Full Full Full

Every browser listed supports this attribute. However, inline event handlers such as this should be avoided. In the same way that inline CSS styles are frowned upon but externally defined CSS styles are considered good practice, inline event handlers should be stripped out and replaced with events attached unobtrusively through the DOM.

Share This Article

Adam Roberts

Adam is SitePoint’s head of newsletters, who mainly writes Versioning, a daily newsletter covering everything new and interesting in the world of web development. He has a beard and will talk to you about beer and Star Wars, if you let him.

Источник

Оцените статью