Detailed explanation of the graphics and text code for implementing the Tooltip floating prompt box effect using native JavaScript

黄舟
Release: 2017-03-22 14:42:05
Original
2853 people have browsed it

This article mainly introduces the nativeJavaScriptdesign and implementation of TooltipFloatingprompt box special effects. It has certain reference value. Interested friends can refer to it.

Use native JavaScript to design and implement Tooltip floating prompt box effects, and learn about code simplification, event binding, event bubbling and other techniques and knowledge.

Four key points of special effects:

Display: When the mouse moves over the ToolTip hyperlink, the ToolTip prompt box can be displayed
Hide: Mouse When moved, the ToolTip prompt box automatically hides
Positioning: The position of the ToolTip prompt box needs to be set according to the position of the ToolTip hyperlink
Configurable: The ToolTip prompt box can change the size and display content according to different parameters

Note:

1) border-radius and box-shadow are compatible with writing methods

2) Regardless of whether the mouse pointer passes through the selected element or its sub-elements, The mouseover event will be triggered. Corresponding to mouseout

The mouseenter event will only be triggered when the mouse pointer passes through the selected element. Corresponding to mouseleave

3)W3Cregulations do not allowinline elementsto nest block-level elements. The a link in it has a nested p, which may not comply with W3C standards ( tip: It was created in the a link when moving the a link. The id gets the DOM reference of the element

var $ = function(id){ return document.getElementById(id); }
Copy after login

2) The function of binding the event

function addEvent(obj,event,fn){ //要绑定的元素对象,要绑定的事件,触发的回调函数 if(obj.addEventListener){ //非IE,支持冒泡和捕获 obj.addEventListenner(event,fn,false); }else if(obj.attachEvent){ //IE,只支持冒泡 obj.attachEvent('on'+event,fn); } }
Copy after login

The effect is as shown:

     

原生JavaScript实现ToolTip效果

ToolTip效果是非常常见的网页特效,它可以在用户将指针放置在控件上时为用户显示提示信息。 比如简称文字显示一行文字全称,例:中国NBA。 又比如显示一段文字,例:唐诗三百首中的春晓你会么?如果不看tooltip提示你背不出来的话,那么你 可要加油了。

ToolTip效果还可以用来显示图片,例:西湖美景。当然显示一块儿带格式的内容也不在话下,例: 我的资料

甚至你可以显示一整个网站:例:慕课网

注意好的ToolTip需要考虑样式、效果、页面的边界等信息,希望你可以做出更漂亮的ToolTip效果。

Copy after login

The above is the detailed content of Detailed explanation of the graphics and text code for implementing the Tooltip floating prompt box effect using native JavaScript. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!