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. 介绍三个Android支持库控件:TabLayout+ViewPager+RecyclerView

    本文主要介绍如下三个Android支持库控件的配合使用: TabLayout:android.support.design.widget.TabLayout ViewPager:android.sup ...

  2. Spring MVC__自定义日期类型转换器

    WEB层采用Spring MVC框架,将查询到的数据传递给APP端或客户端,这没啥,但是坑的是实体类中有日期类型的属性,但是你必须提前格式化好之后返回给它们.说真的,以前真没这样做过,之前都是一口气查 ...

  3. 给我的cnblogs主页做一个响应式布局模板

    在cnblogs,一直都是使用官方自带的那些模板,而且感觉也一直很良好!不过最近用手机搜索一些相关的技术资料,很多都来自cnblogs,有些博主的页面在和机端显得很好,有些则展示得不那么友好了……忽然 ...

  4. SQL Server 跨库复制表方法小笔记

    insert into tableA (column1,column2.....) SELECT * FROM OPENDATASOURCE('SQLOLEDB', 'Data Source=127. ...

  5. 深入理解css中vertical-align属性

    一.为什么要写这篇文章 今天看到一个问题: 两个div 都设置 display:inline-block,正常显示:但是在第二个div中加一个块级元素或者内联元素,显示就变了个样,为什么? <m ...

  6. SpringMVC文件上传下载

    不多说,代码: Spring-config.xml<!-- spring可以自动去扫描base-pack下面的包或者子包下面的java文件, 如果扫描到有Spring的相关注解的类,则把这些类注 ...

  7. 基础SELECT示例掌握

    SELECT查询语句 ---进行单条记录.多条记录.单表.多表.子查询-- SELECT [ALL | DISTINCT | DISTINCTROW ] [HIGH_PRIORITY] [MAX_ST ...

  8. Let's Encrypt: 为CentOS/RHEL 7下的nginx安装https支持-具体案例

    环境说明: centos 7 nginx 1.10.2 前期准备 软件安装 yum install -y epel-release yum install -y certbot 创建目录及链接 方法1 ...

  9. spring学习总结二-----面向切面编程(AOP)思想

    上一篇spring博客简总结了spring控制反转和依赖注入的相关思想知识点,这篇博文对spring的面向切的编程思想进行简单的梳理和总结. 一.面向切面的思想 与面向对象的纵向关系概念不同,面向切面 ...

  10. UBIFS文件系统介绍

    1.  引言 UBIFS,Unsorted Block Image File System,无排序区块图像文件系统.它是用于固态硬盘存储设备上,并与LogFS相互竞争,作为JFFS2的后继文件系统之一 ...