jquery鼠标悬停动态显示提示文字或者图片

 时间:2024-09-20 19:47:34

jquery鼠标悬停动态显示提示文字或者图片

工具/原料

adobedreamweaver

方法/步骤

1、准备好需要用到的图标。

jquery鼠标悬停动态显示提示文字或者图片

2、新建html文档。

jquery鼠标悬停动态显示提示文字或者图片

3、书写hmtl代码。<center><ahref="javascript:"id="ahover"tooltips="这里是hover的tips">鼠标滑过自动显示</a><ahref="#"id="aclick"tooltips="<imgsrc='a.png'>">点击显示提示信息</a></center>

jquery鼠标悬停动态显示提示文字或者图片

4、书写css代码跷孳岔养。<style>*{margin:0;padding:0;}bo颊俄岿髭dy{padding:200px;font-size:12px;background-color:#f0f0f0;}.tooltips{border-width:1px;border-style:solid;position:absolute;display:none;border-radius:3px;opacity:0;filter:alpha(opacity=0);z-index:999;}.tooltipsp.content{padding:5px;}.tooltips.triangle-front,.tooltips.triangle-back{width:0;height:0;overflow:hidden;border-width:8px;border-style:solid;position:absolute;border-color:transparent;top:100%;left:50%;margin-left:-8px;}.tooltips.triangle-back{margin-top:-1px;}.yellow{border-color:#c7c08d;background-color:#fffac3;}.yellow.triangle-front{border-top-color:#c7c08d;}.yellow.triangle-back{border-top-color:#fffac3;}a{padding:5px;margin-right:20px;border:1pxsolid#cc00dd;}</style>

jquery鼠标悬停动态显示提示文字或者图片

5、书写并添加js蜣贺鱿柢代码。<scriptsrc="jquery-1.10.2.min.js"></script><scri禊诬娱飑pt>$.fn.extend({ hoverTips:function(){ varself=$(this); varsw=self.get(0).switch; if(!sw){ sw=true; varcontent=self.attr("tooltips"); varhtmlDom=$("<divclass='tooltips'>") .addClass("yellow") .html("<pclass='content'></p>" +"<pclass='triangle-front'></p>" +"<pclass='triangle-back'></p>"); htmlDom.find("p.content").html(content); } self.on("mouseover",function(){ $("body").append(htmlDom); varleft=self.offset().left-htmlDom.outerWidth()/2+self.outerWidth()/2; vartop=self.offset().top-htmlDom.outerHeight()-parseInt(htmlDom.find(".triangle-front").css("border-width")); htmlDom.css({"left":left,"top":top-10,"display":"block"}); htmlDom.stop().animate({"top":top,"opacity":1},300); }); self.on("mouseout",function(){ vartop=parseInt(htmlDom.css("top")); htmlDom.stop().animate({"top":top-10,"opacity":0},300,function(){ htmlDom.remove(); sw=false; }); }); }, clickTips:function(){ varself=$(this); varsw=self.get(0).switch; if(!sw){ sw=true; varcontent=self.attr("tooltips"); varhtmlDom=$("<divclass='tooltips'>") .addClass("yellow") .html("<pclass='content'></p>" +"<pclass='triangle-front'></p>" +"<pclass='triangle-back'></p>"); htmlDom.find("p.content").html(content); } self.on("click",function(){ $("body").append(htmlDom); varleft=self.offset().left-htmlDom.outerWidth()/2+self.outerWidth()/2; vartop=self.offset().top-htmlDom.outerHeight()-parseInt(htmlDom.find(".triangle-front").css("border-width")); htmlDom.css({"left":left,"top":top-10,"display":"block"}); htmlDom.stop().animate({"top":top,"opacity":1},300,function(){ setTimeout(function(){ htmlDom.stop().animate({"top":top-10,"opacity":0},300,function(){ htmlDom.remove(); sw=false; }) },2000) }); }) }});$("#ahover").hoverTips();$("#aclick").clickTips();</script>

jquery鼠标悬停动态显示提示文字或者图片

6、代码整体结构。

jquery鼠标悬停动态显示提示文字或者图片

7、查看效果。

jquery鼠标悬停动态显示提示文字或者图片

前端编程-用浏览器自带的取色功能快速拾取颜色 如何用CSS修改不同input标签的样式 onchange()事件不触发 不起作用 HTML表单教程 多选项的详解 python中设计类的三要素是什么
热门搜索
动漫绘画教程 老师简笔画图片大全 动漫美女被褥漫画 眷念你的温柔 动漫 动漫美图壁纸