新鮮出爐的js tips提示效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<body>
<br><br><br><br><br><br><br><br>
<input id='test'>
<br><br><br><br><br><br><br><br>
<a href='#' id='test2' onmouseover="tips.show('普通鏈接或按鈕提示-灰色-鼠標(biāo)離開(kāi)消失-300像素', 'test2', null, '#000000', 300)" onmouseout="tips.hidden('test2')">普通鏈接或按鈕提示</a>
<script>
//提示消息類(lèi)
var tips = {
temp : {},
/***
* 彈出提示
*
* @param string msg 提示文字內(nèi)容
* @param string id 要彈出提示的目標(biāo)對(duì)象的id,如果id錯(cuò)誤/null/false/0則主窗口彈出
* @param int time 定時(shí)消失時(shí)間毫秒數(shù),如果為null/0/false則不定時(shí)
* @param string color 提示內(nèi)容的背景顏色格式為#000000
* @param int width 提示窗寬度,默認(rèn)300
*/
show : function(msg, id, time, color, width)
{
var target = this._get(id);
if(!target) { id = 'window'; }
//如果彈出過(guò)則移除重新彈出
if(this._get(id+'_tips')) { this.remove(id); }
//設(shè)置默認(rèn)值
msg = msg || 'error';
color = color || '#ea0000';
width = width || 300;
time = time ? parseInt(time) : false;
if(id=='window') {
var y = document.body.clientHeight/2+document.body.scrollTop;
var x = (document.body.clientWidth-width)/2;
var textAlign = 'center', fontSize = '15',fontWeight = 'bold';
} else {
//獲取對(duì)象坐標(biāo)信息
for(var y=0,x=0; target!=null; y+=target.offsetTop, x+=target.offsetLeft, target=target.offsetParent);
var textAlign = 'left', fontSize = '12',fontWeight = 'normal';
}
//彈出提示
var tipsDiv = this._create({display:'block',position:'absolute',zIndex:'1001',width:(width-2)+'px',left:(x+1)+'px',padding:'5px',color:'#ffffff',fontSize:fontSize+'px',backgroundColor:color,textAlign:textAlign,fontWeight:fontWeight,filter:'Alpha(Opacity=50)',opacity:'0.7'}, {id:id+'_text', innerHTML:msg, onclick:function(){tips.hidden(id);}});
document.body.appendChild(tipsDiv);
tipsDiv.style.top = (y-tipsDiv.offsetHeight-12)+'px';
document.body.appendChild(this._create({display:'block',position:'absolute',zIndex:'1000',width:(width+10)+'px',height:(tipsDiv.offsetHeight-2)+'px',left:x+'px',top:(y-tipsDiv.offsetHeight-11)+'px',backgroundColor:color,filter:'Alpha(Opacity=50)',opacity:'0.7'}, {id:id+'_bg'}));
if(id!='window') {
var arrow = this._create({display:'block',position:'absolute',overflow:'hidden',zIndex:'999',width:'20px',height:'10px',left:(x+20)+'px',top:(y-13)+'px'}, {id:id+'_arrow'});
arrow.appendChild(this._create({display:'block',overflow:'hidden',width:'0px',height:'10px',borderTop:'10px solid '+color,borderRight:'10px solid #fff', borderLeft:'10px solid #fff',filter:'Alpha(Opacity=70)',opacity:'0.8'}));
document.body.appendChild(arrow);
}
//標(biāo)記已經(jīng)彈出
this.temp[id] = id;
//如果定時(shí)關(guān)閉
if(time) { setTimeout(function(){tips.hidden(id);}, time) }
return id;
},
/***
* 隱藏提示
*
* @param string id 要隱藏提示的id,如果要隱藏主窗口提示id為window,如果要隱藏所有提示id為空即可
*/
hidden : function(id)
{
if(!id) { for(var i in this.temp) { this.hidden(i); } return; }
var t = this._get(id+'_text'), d = this._get(id+'_bg'), a = this._get(id+'_arrow');
if(t) { t.parentNode.removeChild(t); }
if(d) { d.parentNode.removeChild(d); }
if(a) { a.parentNode.removeChild(a); }
},
_create : function(set, attr)
{
var obj = document.createElement('div');
for(var i in set) { obj.style[i] = set[i]; }
for(var i in attr) { obj[i] = attr[i]; }
return obj;
},
_get : function(id)
{
return document.getElementById(id);
}
};
window.onload = function(){
tips.show('主窗口提示-綠色-不定時(shí)-300像素', null, null, '#009900', 300);
tips.show('表單報(bào)錯(cuò)提示-紅色-3000毫秒消失-250像素', 'test', 3000, '#ea0000', 250);
}
document.onclick = function(){
tips.hidden();
}
</script>
- Some tips of wmi scripting in jscript (1)
- ASP小貼士/ASP Tips javascript tips可以當(dāng)桌面
- JavaScript Tips 使用DocumentFragment加快DOM渲染速度
- javascript tips提示框組件實(shí)現(xiàn)代碼
- JavaScript Title、alt提示(Tips)實(shí)現(xiàn)源碼解讀
- jQuery懸停文字提示框插件jquery.tooltipster.js用法示例【附demo源碼下載】
- JavaScript調(diào)試的多個(gè)必備小Tips
- bootstrap tooltips在 angularJS中的使用方法
- 總結(jié)分享10個(gè)JavaScript代碼優(yōu)化小tips
相關(guān)文章
微信頁(yè)面彈出鍵盤(pán)后iframe內(nèi)容變空白的解決方案
當(dāng)鍵盤(pán)彈出后,頁(yè)腳也被頂起來(lái);而當(dāng)搜索完(要刷新整體頁(yè)面),鍵盤(pán)縮回后,iframe里 鍵盤(pán)當(dāng)住的地方變成白色。怎么解決這個(gè)問(wèn)題呢?下面腳本之家小編給大家分享微信頁(yè)面彈出鍵盤(pán)后iframe內(nèi)容變空白的解決方案,一起看看吧2017-09-09es6學(xué)習(xí)之解構(gòu)時(shí)應(yīng)該注意的點(diǎn)
解構(gòu)賦值允許你使用類(lèi)似數(shù)組或?qū)ο笞置媪康恼Z(yǔ)法將數(shù)組和對(duì)象的屬性賦給各種變量。這種賦值語(yǔ)法極度簡(jiǎn)潔,同時(shí)還比傳統(tǒng)的屬性訪(fǎng)問(wèn)方法更為清晰,下面這篇文章主要給大家介紹了關(guān)于在es6解構(gòu)時(shí)應(yīng)該注意的點(diǎn),需要的朋友可以參考下。2017-08-08js中select選擇器的change事件處理函數(shù)詳解
Js操作Select是很常見(jiàn)的,也是比較實(shí)用的,下面這篇文章主要給大家介紹了關(guān)于js中select選擇器的change事件處理函數(shù)的相關(guān)資料,文中給出了詳細(xì)的實(shí)例代碼,需要的朋友可以參考下2023-06-06微信小程序進(jìn)入廣告實(shí)現(xiàn)代碼實(shí)例
這篇文章主要介紹了微信小程序進(jìn)入廣告實(shí)現(xiàn)代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09怎么讓腳本或里面的函數(shù)在所有圖片都載入完畢的時(shí)候執(zhí)行
怎么讓腳本或里面的函數(shù)在所有圖片都載入完畢的時(shí)候執(zhí)行...2006-10-10僅用[]()+!等符號(hào)就足以實(shí)現(xiàn)幾乎任意Javascript代碼
僅用一些符號(hào)就足以實(shí)現(xiàn)幾乎任意Javascript代碼的方法,比較怪異,對(duì)于特殊需要可能用得到。2010-03-03javascript Excel操作知識(shí)點(diǎn)
使用JavaScript中的ActiveXObject填充并設(shè)置Excel格式2009-04-04JavaScript使用RegExp進(jìn)行正則匹配的方法
這篇文章主要介紹了JavaScript使用RegExp進(jìn)行正則匹配的方法,實(shí)例分析了RegExp對(duì)象在進(jìn)行正則匹配時(shí)的相關(guān)使用技巧,需要的朋友可以參考下2015-07-07layer iframe 設(shè)置關(guān)閉按鈕的方法
今天小編就為大家分享一篇layer iframe 設(shè)置關(guān)閉按鈕的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09