您的位置:首页 > Web前端 > JavaScript

js提示小插件

2014-09-19 18:07 85 查看
/*
*提示插件
*使用方法:showTip('提示内容',3)
*/

var tip = null;

//显示提示文本,text为要显示的文本,second表示自动消失的秒数
function showTip(text,second){
	
	if(!tip){
		tip = document.createElement('div');
		tip.style.backgroundColor = '#000';
		tip.style.color = '#fff';
		tip.style.fontSize = '18px';
		tip.style.fontWeight = 'bold';
		tip.style.fontFamily = '微软雅黑';
		tip.style.width = 'auto';
		tip.style.height = 'auto';
		tip.style.padding = '10px 30px 10px 30px';
		tip.style.borderRadius = '6px';
		tip.style.opacity = '0.7';
		tip.style.position = 'fixed';
		tip.style.zIndex = '99999';
		document.body.appendChild(tip);
	}
	tip.innerHTML = text;
	tip.style.display = 'inline-block';

	tip.style.top = (document.documentElement.clientHeight/2 - tip.offsetHeight/2) + 'px';
	tip.style.left = (document.documentElement.clientWidth/2 - tip.offsetWidth/2) + 'px';
	
	setTimeout(function disappear(){
		tip.style.display = 'none';
	},second*1000);
	
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐