Home Web Front-end JS Tutorial javascript practical text chain prompt box effect_text special effects

javascript practical text chain prompt box effect_text special effects

May 16, 2016 pm 06:24 PM
Prompt box

The effect should basically realize the following functions:
(1) When the mouse slides over the link text in the article, a prompt box will pop up at the corresponding position. The style of the prompt box is controlled by CSS and is highly adaptive; the mouse can click on the middle of the prompt box The link will automatically disappear when you slide away from the prompt box;
(2) Control the position of the prompt box within the text field. If the link text is on the left side of the text field, the prompt box should be displayed on the right, so that It will not leave the text field; on the contrary, if the link text is on the right side of the text field, the prompt box should be displayed on the left;
(3) If the text field has a lot of content and the link text happens to be at the bottom of the browser, in order to make the prompt The box should not leave the visible range of the browser, and the position of the prompt box should be automatically adjusted above the link text;

1.css

Copy Code The code is as follows:

.main{width:950px; border:#9C3 1px solid; margin:0 auto; padding:15px; background-color:# fff; line-height:25px;font-size:14px; position:relative;}
span{border:#70bce4 2px solid; display:block; position:absolute; background-color:#FFF; padding:5px 10px ; font-size:12px; width:200px; display:none;}
.cur{color:#900;}

2.js
Copy code The code is as follows:

//Function to get object elements;
function $a(id,tag){var re =(id&&typeof id!="string")?id:document.getElementById(id);if(!tag){return re;}else{return re.getElementsByTagName(tag);}}
function tips(){
//Get the list of a elements in the text field;
var article=$a("article","a")
for(i=0;i//Traverse a elements, a elements that do not contain class "cur" will not execute the subsequent code;
if(article[i].className.indexOf("cur")==-1) continue;
article[i].onmouseover=function(e){
//Get the coordinates of the mouse pointer in the browser's visible area, not affected by the document content;
var e=e||event;
posX = e.clientX;
posY = e.clientY;
//Get the height of the browser’s visible area;
var bodyhe=document.documentElement.clientHeight;
var parwidth=$a ("article").offsetWidth;
var tipbox=get_nextSibling(this);
var boxlist=$a("article","span")
//Set the span tip box in the text area It is hidden state;
for(j=0;jboxlist[j].style.display="none";
boxlist[j].innerHTML=" Enter background data"
}
//Set the current tip box display;
tipbox.style.display="block";
var w=tipbox.offsetWidth-this.offsetWidth;
/*
The div with the id as article has relative positioning: relative added, so it is already the parent of the tip box;
Control the display position of the pop-up box;
*/
tipbox.style .left=(this.offsetLeft>parwidth/2?this.offsetLeft-w:this.offsetLeft) "px";
tipbox.style.top=(posY tipbox.offsetHeight>bodyhe?this.offsetTop-tipbox.offsetHeight :document.all?this.offsetTop 15:this.offsetTop this.offsetHeight) "px";
tipbox.onmouseover=function(){this.style.display="block";}
tipbox.onmouseout= this.onmouseout=function(){tipbox.style.display="none";}
}
}
}
//Get the next label node of the object element;
function get_nextSibling (n){
var x=n.nextSibling;
while (x.nodeType!=1){
x=x.nextSibling;
}
return x;
}

Friends who are interested in posting the source file code can test it. If you have any questions, please leave a message@&@
Copy the code The code is as follows:





Prompt box effect





< br />




Before the incident broke out, Edison Chen's father was rumored to be supporting mainland actor Hu Bing. As the saying goes, there is no smoke without fire. The two were once photographed by the media eating and shopping together. AndHu BingDouble-fire gun Shanghai starts
Double-fire gun Shanghai starts up
Double-fire cannon starts up in Shanghai
My ambiguous attitude also added to the mystery of this incident. Long before the Edison Chen "pornographic photo scandal" broke out, Edison Chen's father was rumored to be supporting mainland actor Hu Bing. As the saying goes, there is no smoke without fire. The two were once photographed by the media eating and shopping together. AndHu BingDouble-fire gun Shanghai starts
Double-fire gun Shanghai starts up
Double-fire cannon starts up in Shanghai
My ambiguous attitude also added to the mystery of this incident. Long before the Edison Chen "pornographic photo scandal" broke out, Edison Chen's father was rumored to be supporting mainland actor Hu Bing. As the saying goes, there is no smoke without fire. The two were once photographed by the media eating and shopping together. AndHu BingDouble-fire gun Shanghai starts
Double-fire gun Shanghai starts up
Double-fire cannon starts up in Shanghai
My ambiguous attitude also added to the mystery of this incident.





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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do I create and publish my own JavaScript libraries? How do I create and publish my own JavaScript libraries? Mar 18, 2025 pm 03:12 PM

Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

How do I optimize JavaScript code for performance in the browser? How do I optimize JavaScript code for performance in the browser? Mar 18, 2025 pm 03:14 PM

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

How do I debug JavaScript code effectively using browser developer tools? How do I debug JavaScript code effectively using browser developer tools? Mar 18, 2025 pm 03:16 PM

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

How do I use source maps to debug minified JavaScript code? How do I use source maps to debug minified JavaScript code? Mar 18, 2025 pm 03:17 PM

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

How do I use Java's collections framework effectively? How do I use Java's collections framework effectively? Mar 13, 2025 pm 12:28 PM

This article explores effective use of Java's Collections Framework. It emphasizes choosing appropriate collections (List, Set, Map, Queue) based on data structure, performance needs, and thread safety. Optimizing collection usage through efficient

TypeScript for Beginners, Part 2: Basic Data Types TypeScript for Beginners, Part 2: Basic Data Types Mar 19, 2025 am 09:10 AM

Once you have mastered the entry-level TypeScript tutorial, you should be able to write your own code in an IDE that supports TypeScript and compile it into JavaScript. This tutorial will dive into various data types in TypeScript. JavaScript has seven data types: Null, Undefined, Boolean, Number, String, Symbol (introduced by ES6) and Object. TypeScript defines more types on this basis, and this tutorial will cover all of them in detail. Null data type Like JavaScript, null in TypeScript

Getting Started With Chart.js: Pie, Doughnut, and Bubble Charts Getting Started With Chart.js: Pie, Doughnut, and Bubble Charts Mar 15, 2025 am 09:19 AM

This tutorial will explain how to create pie, ring, and bubble charts using Chart.js. Previously, we have learned four chart types of Chart.js: line chart and bar chart (tutorial 2), as well as radar chart and polar region chart (tutorial 3). Create pie and ring charts Pie charts and ring charts are ideal for showing the proportions of a whole that is divided into different parts. For example, a pie chart can be used to show the percentage of male lions, female lions and young lions in a safari, or the percentage of votes that different candidates receive in the election. Pie charts are only suitable for comparing single parameters or datasets. It should be noted that the pie chart cannot draw entities with zero value because the angle of the fan in the pie chart depends on the numerical size of the data point. This means any entity with zero proportion

See all articles