欢迎您光临自学哈网,只为分享网络知识教程,供大家学习参考!

「自学哈网」为WordPress网站上的链接添加一个醒目的提示

作者 : 自学哈 本文共1812个字,预计阅读时间需要5分钟 2022-11-6 共133人阅读
也想出现在这里? 联系我们

为Wordpress网站上的链接添加一个醒目的提示

在Wordpres网站上,当鼠标移动到超链接,会浮现一个醒目的提醒,这是如何做的?

可能你发现很多童鞋的博客的链接上会弹出一个半透明的醒目提示,这是通过Sweet Titles标题增强插件实现的.

Sweet Titles 这个名字源自于一个改变 Title 提示效果的 js 插件 Sweet Titles Finalized。此插件不但让你的 title 提示效果变得美观,而且可以显示出你将要点击的链接的 url,让用户知道自己将要去哪里,同时提升了用户感受度。另外,系统的 title 提示有时间延迟,利用 js 可以迅速的展示出来。

不过个人感觉这个特效有点鸡肋,反而会干扰视线,影响浏览者阅读。

插件加载的JS文件有点大5K多,而Leeiio童鞋提供的简化代码,只有不到2K,如果你喜欢这个效果那就加上吧(代码中符号冲突,被表情替代,但不会影响复制使用):

var sweetTitles = {x : 10, // @Number: x pixel value of current cursor positiony : 20, // @Number: y pixel value of current cursor positiontipElements : "a", // @Array: Allowable elements that can have the toolTip,split with ","noTitle : true, //if this value is false,when the elements has no title,it will not be showinit : 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.myHref = this.href;this.myHref = (this.myHref.length > 30 ? this.myHref.toString().substring(0,30)+"..." : this.myHref);this.title = "";var tooltip = "<div id='tooltip'><p>"+this.myTitle+"<em>"+this.myHref+"</em>"+"</p></div>";$('body').append(tooltip);$('#tooltip').css({"opacity":"0.8","top":(e.pageY+20)+"px","left":(e.pageX+10)+"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+10)+"px"});});});}};$(function(){sweetTitles.init();});

代码很简洁,前提是你的主题已加载了 jQuery 库。

有效果没有样式还不行,而要添加 css 样式才能让整个效果显得更加美妙。以下是 css样式供参考。

body div#tooltip { position:absolute;z-index:1000;max-width:220px;width:auto !important;width:220px;background:#000;text-align:left;padding:5px;min-height:1em;}body div#tooltip p { margin:0;padding:0;color:#fff;font:12pxverdana,arial,sans-serif; }body div#tooltip p em { display:block;margin-top:3px;color:#f60;font-style:normal;font-weight:bold; }
本站声明:
本站所有资源来源于网络,分享目的仅供大家学习和交流!如若本站内容侵犯了原著者的合法权益,可联系邮箱976157886@qq.com进行删除。
自学哈专注于免费提供最新的分享知识、网络教程、网络技术的资源分享平台,好资源不私藏,大家一起分享!

自学哈网 » 「自学哈网」为WordPress网站上的链接添加一个醒目的提示
也想出现在这里? 联系我们
© 2022 Theme by - 自学哈网 & WordPress Theme. All rights reserved 浙ICP备2022016594号