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

WBOY
WBOYOriginal
2016-05-16 18:24:08831browse

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:
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