html代码

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>提示框</title>
<script src="../jquery-1.10.2.min.js" type="text/javascript" charset="utf-8" ></script>
<script src="tip.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="tip.css">
<style type="text/css" media="screen">
.box,.box1,.box3,.box4 {width: 100px;height:20px;text-align: center;color: #000;border:1px solid #dcdcdc;}
.box1{margin:0 auto;}
.box2{width: 50px;height: 20px;text-align: center;color: #000;border:1px solid #000;position: absolute;right:200px;top:200px;overflow: hidden;}
.box3 {margin-top: 200px;}
.box4 {position: absolute;right:0px;top:300px;}
</style>
<script type="text/javascript" charset="utf-8">
$(function(){
$(".box").m_tip(".m_tip",true);
$(".box1").m_tip(".m_tip",false);
$(".box2").m_tip(".m_tip",false);
$(".box3").m_tip(".m_tip",false);
$(".box4").m_tip(".m_tip",false);
})
</script>
</head> <body>
<div class="box" data-direction="bottom">提示框移动</div>
<div class="box1" data-direction="left">提示框移动</div>
<div class="box2" data-direction="left">提示框移动</div>
<div class="box3" data-direction="right">提示框移动</div>
<div class="box4" data-direction="left">提示框移动</div><div class="m_tip"> <div class="m_tip_bottom" data-border="6"></div> <span>文字文字</span></div></body></html> css代码
*{margin:0px;padding:0px;}
.m_tip {
background: #555556 none repeat scroll 0 0;
color: #fff;
font-size: 12px;
min-height: 20px;
line-height: 20px;
position: absolute;
text-align: center;
min-width: 45px;
display: none;
padding:4px;
z-index: 1000;
}
.m_tip_bottom {
border-left: 6px solid #fff;
height: 0;
line-height: 0;
position: absolute;
width: 0;
} js代码
$(function(){
//target表示提示框的class tag的取值为true or false 用来表示是否显示提示框的边框圆角
$.fn.m_tip = function(target,tag){
var that = $(this);
that.hover(function(){
var border = parseInt($(target).find(".m_tip_bottom").attr("data-border"));
var b_w=that.outerWidth();
var b_h=that.outerHeight();
var t_w=$(target).outerWidth();
var t_h=$(target).outerHeight();
var o_L=that.offset().left;
var o_T=that.offset().top;
var m_L=that.offset().left + (b_w - t_w) / 2;
var m_T=that.offset().top - b_h - border -3; //判断是否显示边框圆角
if( tag ) {
$(target).css("border-radius",'3px');
} else {
$(target).css("border-radius",'0px');
}
// 判断提示框显示的方向
//
if( that.attr("data-direction") == 'bottom') {
$(target).find(".m_tip_bottom").css({
'border-bottom' : "6px solid #555556",
'border-top' : '0px',
'border-left' : '6px solid #fff',
'border-right' : '6px solid #fff',
'top': -border,
'left': t_w / 2 -border
})
$(target).css({
top: o_T + t_h,
left: m_L
})
} else if( that.attr("data-direction") == 'top' ) {
$(target).find(".m_tip_bottom").css({
'border-top' : "6px solid #555556",
'border-bottom' : '0px',
'border-left' : '6px solid #fff',
'border-right' : '6px solid #fff',
'left' : t_w / 2 -border,
'top' : t_h
})
$(target).css({
left:m_L,
top:m_T
})
} else if( that.attr("data-direction") == 'right' ) {
$(target).find(".m_tip_bottom").css({
'border-top' : "6px solid #fff",
'border-bottom' : '6px solid #fff',
'border-left' : '0px',
'border-right' : '6px solid #555556',
'left' : - border,
'top' : ( t_h - border ) / 2 -3
})
$(target).css({
left:b_w + border,
top:o_T - ( t_h - b_h ) / 2
})
} else if( that.attr("data-direction") == 'left' ) {
$(target).find(".m_tip_bottom").css({
'border-top' : "6px solid #fff",
'border-bottom' : '6px solid #fff',
'border-left' : '6px solid #555556',
'border-right' : '0px',
'left' : t_w,
'top' : ( t_h - border ) / 2 -3
})
$(target).css({
left:o_L - t_w - border,
top:o_T - ( t_h - b_h ) / 2
})
}
$(target).show();
},function(){
$(target).hide();
})
} })

一个可以控制提示框显示为top,bottom,left,right的小方法的更多相关文章

  1. 自适应文案提示框、无数据图片加载<IOS小组件>

    非常感谢,帮助我的朋友们,谢谢你们. 该组件的编写仅仅用来不到4个小时,包括测试与修改bug.为他起名为AdaptivePromptDialogBox(就是自适应文案提示框): 呆毛地址:链接 < ...

  2. ASP.NET div信息提示框显示几秒后隐藏

    今天在旧系统中,用户要求,要把一个javascript alert的信息提示,改为Div tag来显示,它在显示时,仅显示几秒,然后隐藏,这样无需用户去点击alert信息框的确定或是关闭铵钮. 下面I ...

  3. Android 入门第一课 一个简单的提示框

    1.打开Android开发环境Eclipse来到主界面 2.新建一个安卓项目 File->New->Android Application project 在上面有红色错误的地方填上应用程 ...

  4. oracle之 安装oracle指定jdk 或者如何解决提示框显示不全

    在centos7下,安装oracle 11g. gnome的桌面.各个参数配置好后,运行runInstaller命令.此时弹出安装界面,在一次次点击[下一步]的时候,中间会弹出对话框,可是对话框显示不 ...

  5. android7.0后对于detected problems with app native libraries提示框显示

    log信息: 03-27 09:08:25.887   397   400 W linker  : /data/app/com.guagua.qiqi-1/lib/arm/libMedia.so ha ...

  6. 玩魔兽争霸无故退出 提示框显示"0x21101663"指令引用的"0x02704acc"内存该存不能为"read" 确定就会终止程序

    20151002总结:下方法试过,没完全按照说的操作完,觉得有风险且那个read程序执行时间好长的,感觉有点干坏事的意思 ======================================= ...

  7. mongodb GridFS django FileFiled 默认 widget 只有一个文件上传框显示不了字段内容,重写widget

    首先,定位到:FileFiled 默认 widget 源码:mongoadmin包options.py中,如下: # Defaults for formfield_overrides. ModelAd ...

  8. 【Unity笔记】提示框ToolTips大小自适应,及其闪烁的问题

    需求:制作了一个提示框,当鼠标移入背包格子内,显示提示框,且提示框位置跟随鼠标移动.当鼠标移出背包格子,隐藏提示框. 制作提示框ToolTips 因为提示框的大小要求随着显示的文本内容长度而自动大小适 ...

  9. ASP.NET 使用AJAX让GridView的数据行显示提示框(ToolTip)

    介绍ASP.NET AJAX可以使你的web应用程序具有更丰富的功能和更多的用户响应. 本文中,我将演示如何通过ASP.NET AJAX的帮助,给像GridView这样的数据绑定控件的数据行增加pop ...

随机推荐

  1. 找到一个新的超好用的U盘启动制作工具了

    有同事叫帮装电脑,弄个U盘说制作一个启动盘,结果一搜,出了“雨林木风”的主页. 太好用了,高手的产物,比以前找的方便一百倍.又简单,又实用,同步又下载好GHO文件.唯一 的问题是XP中用的GHO,好多 ...

  2. linux下如何查看mysql、apache是否安装,并卸载

    --linux下如何查看mysql.apache是否安装,并卸载? http://blog.163.com/dengxiuhua126@126/blog/static/1186077720137311 ...

  3. Unity Debug类

    静态变量 developerConsoleVisible 报告是否开发控制台是可见的.开发控制台不能出现使用: isDebugBuild 在构建设置对话框中有一个叫做"发展构建"复 ...

  4. JDBC访问数据库

    一.准备条件 外界条件 在数据库中首先创建表空间 在创建的表中添加数据 代码部分 导入数据库的驱动包(jar) 加载数据库驱动 获取数据库连接 编写sql语句 利用prepareStatement进行 ...

  5. Asp.NET MVC 之心跳/长连接

    0x01 在线用户类,我的用户唯一性由ID和类型识别(因为在不同的表里) public class UserIdentity : IEqualityComparer<UserIdentity&g ...

  6. [ext4]03 磁盘布局 – Flexible group分析

    Flexible Block Groups (flex_bg),我称之为"弹性块组",是EXT4文件系统引入的一个feature. 所谓Flexible Block Groups, ...

  7. javascript 六种数据类型(一)

    js的数据类型和常见隐式转化逻辑. 一.六种数据类型 原始类型(基本类型):按值访问,可以操作保存在变量中实际的值.原始类型汇总中null和undefined比较特殊. 引用类型:引用类型的值是保存在 ...

  8. win彩 百款皮肤任选任换.可视化

  9. vuex使用报错

    1.vuex简介 最近在玩vuex,不得不说它是一个很强大的工具,它的目的就是把数据统一管理起来,方便各个组件之间来回调用 2.vuex引用报错 当我们去官网看API文档的时候,会发现官网是这么应用a ...

  10. ASP.Net WebAPI与Ajax进行跨域数据交互时Cookies数据的传递

    前言 最近公司项目进行架构调整,由原来的三层架构改进升级到微服务架构(准确的说是服务化,还没完全做到微的程度,颗粒度没那么细),遵循RESTFull规范,使前后端完全分离,实现大前端思想.由于是初次尝 ...