分享好友 教程首页 教程搜索 频道列表

美化title属性,使title成为提示框

2019-02-25 10:1611861
+关注2
核心提示:使用方法很简单,引入jq,复制页面底部js和头部样式即可演示

使用方法很简单,引入jq,复制页面底部js和头部样式即可

演示:http://www.jq22.com/demo/jquerytitle201902210123/

效果

HTML

<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=yes" />
		<title>美化title属性,使title成为提示框</title>
		<script src="https://www.jq22.com/jquery/jquery-1.7.1.js"></script>
		<style type="text/css">
			.style{width: 700px;margin: auto;font-size: 18px;color: cadetblue;}
			.tooltip {
				font-size: 12px;
				font-family: \5b8b\4f53;
				line-height: 1.5;
				position: absolute;
				padding: 5px;
				z-index: 100003;
				opacity: .8
			}

			.tipsy-arrow {
				position: absolute;
				width: 0;
				height: 0;
				line-height: 0;
				border: 6px dashed #FFA500;
				top: 0;
				left: 20%;
				margin-left: -5px;
				border-bottom-style: solid;
				border-top: 0;
				border-left-color: transparent;
				border-right-color: transparent
			}

			.tipsy-arrow-n {
				border-bottom-color: #FFA500;
			}

			.tipsy-inner {
				background-color: #FFA500;
				color: #fff;
				max-width: 200px;
				padding: 5px 8px 4px 8px;
				text-align: center;
				border-radius: 3px
			}
		</style>
	<body>
		<div class="style">
			<p>提示:本效果是利用title属性制作的提示框效果,不是真正的提示弹出框</p>
			<a href="#" title="我是提示文字">提示文字</a>
			<a href="#" title="<p>我是提示文字1</p><p>我是提示文字2</p>">提示文字可换行</a>
		</div>
		<script>
			jQuery(document).ready(function($) {
				var sweetTitles = {
					x: 10,
					y: 20,
					tipElements: "a,span,img,div ",
					noTitle: false,
					init: function() {
						var noTitle = this.noTitle;
						$(this.tipElements).each(function() {
							$(this).mouseover(function(e) {
								if (noTitle) {
									isTitle = true;
								} else {
									isTitle = $.trim(this.title) != '';
								}
								if (isTitle) {
									this.myTitle = this.title;
									this.title = "";
									var tooltip =
										"<div class='tooltip'><div class='tipsy-arrow tipsy-arrow-n'></div><div class='tipsy-inner'>" + this.myTitle +
										"</div></div>";
									$('body').append(tooltip);
									$('.tooltip').css({
										"top": (e.pageY + 20) + "px",
										"left": (e.pageX - 20) + "px"
									}).show('fast');
								}
							}).mouseout(function() {
								if (this.myTitle != null) {
									this.title = this.myTitle;
									$('.tooltip').remove();
								}
							}).mousemove(function(e) {
								$('.tooltip').css({
									"top": (e.pageY + 20) + "px",
									"left": (e.pageX - 20) + "px"
								});
							});
						});
					}
				};
				$(function() {
					sweetTitles.init();
				});
			});
		</script>
	</body>
</html>


重点的加入js

<script>
	jQuery(document).ready(function($) {
		var sweetTitles = {
			x: 10,
			y: 20,
			tipElements: "a,span,img,div",
			noTitle: false,
			init: function() {
				var noTitle = this.noTitle;
				$(this.tipElements).each(function() {
					$(this).mouseover(function(e) {
						if (noTitle) {
							isTitle = true;
						} else {
							isTitle = $.trim(this.title) != '';
						}
						if (isTitle) {
							this.myTitle = this.title;
							this.title = "";
							var tooltip =
							"<div class='tooltip'><div class='tipsy-arrow tipsy-arrow-n'></div><div class='tipsy-inner'>" + this.myTitle +
							"</div></div>";
							$('body').append(tooltip);
							$('.tooltip').css({
								"top": (e.pageY + 20) + "px",
								"left": (e.pageX - 20) + "px"
							}).show('fast');
						}
					}).mouseout(function() {
						if (this.myTitle != null) {
							this.title = this.myTitle;
							$('.tooltip').remove();
						}
					}).mousemove(function(e) {
						$('.tooltip').css({
							"top": (e.pageY + 20) + "px",
							"left": (e.pageX - 20) + "px"
						});
					});
				});
			}
		};
		$(function() {
			sweetTitles.init();
		});
	});
</script>

本文标签: #提示 #标题
整理员:网络转载
免责声明:凡注明来源本网的所有作品,均为本网合法拥有版权或有权使用的作品,欢迎转载,注明出处。非本网作品均来自互联网,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。
生成海报
相关评论1
您可能在找更多

微信公众号后台基本配置点击保存总是提示请求url超时,监测网络包发现微信并没有将请求提交到服务后台?

    遇到这个问题,检查一下服务器的防火墙,防火墙误把腾讯进来的IP识别成国外IP,导致调不通,在服务器上关闭防火墙即可

小黑 随手记2023-12-17

DESTOON提示您的帐号在别处登录,您被迫下线

    进入后台,网站设置,安全中心,同一帐号同时异地登录允许:允许会员同时异地登录,不会再有此提示仅限前台:不允许会员同时异地登录后台,会员后台异地登录有此提示完全禁止:不允许会员同时异地登录,会员前后台异

网络转载 随手记2023-06-08

JS实现网页标题随机显示名人名言的方法

    这段代码实现每次刷新过后,网页的标题都会随机显示名人名言,一次一条,把这些名言定义在Javascript的数组内,每次调用随机调用一条,随机产生的随机数正好是数组的标号,这样就实现了随机,不错的效果吧。

小黑 JavaScript教程2022-09-03

手机端绑定二级域名后提示验证码错误的解决方案

    方案有如下几种1、设置cookie作用域。

小黑 destoon设置相关2022-02-28

下一篇
我来说两句
1