在界面上有时需要显示一个提示,大多的前端框架都把提示做成一个带有小尖角的提示框,因此自己也仿照了实现了一下,效果图如下:

尖角的实现很简单的,一般都是通过css将div的宽高设置为0,然后将尖角朝向的那一边的边的宽度设置为0,然后给两边的边框设置宽度为一个大于0的数字,并将颜色设置为透明,然后将剩余的一边框设置宽度和颜色即可。

下面是我的实现方式:

首先是对应的HTML文件:

<!DOCTYPE>
<html>
<head>
<title>tip_demo</title>
<link rel="stylesheet" href="css/tip.css">
<script src="js/jquery-2.2.3.js"></script>
<script src="js/tip.js"></script>
<script>
$(function(){
leftTip();
rightTip();
topTip();
bottomTip();
});
</script>
<style>
.tip-left, .tip-right, .tip-top, .tip-bottom
{
width:250px;
}
</style>
</head>
<body>
<div class="tip-left">
This is left arrow tip
</div>
<br>
<div class="tip-right">
This is right arrow tip
</div>
<br>
<div class="tip-top">
This is top arrow tip
</div>
<br>
<div class="tip-bottom">
This is bottom arrow tip
</div>
</body>
</html>

CSS文件:

.tip-left-arrow
{
width:;
height:;
border-left:0px solid transparent;
border-top:5px solid transparent;
border-right:10px solid gray;
border-bottom:5px solid transparent;
display:inline-block;
} .tip-left-content
{
display:inline-block;
height:50px;
line-height:50px;
vertical-align:middle;
background-color:gray;
border-radius:10px;
padding:5px;
padding-left:10px;
text-align:left;
} .tip-right-arrow
{
width:;
height:;
border-right:0px solid transparent;
border-top:5px solid transparent;
border-left:10px solid gray;
border-bottom:5px solid transparent;
display:inline-block;
} .tip-right-content
{
display:inline-block;
height:50px;
line-height:50px;
vertical-align:middle;
background-color:gray;
border-radius:10px;
padding:5px;
padding-right:10px;
text-align:right;
} .tip-top-arrow
{
width:;
height:;
border-top:0px solid transparent;
border-left:5px solid transparent;
border-bottom:10px solid gray;
border-right:5px solid transparent;
display:inline-block;
} .tip-top-content
{
height:50px;
line-height:50px;
vertical-align:middle;
background-color:gray;
border-radius:10px;
padding:5px;
padding-left:10px;
} .tip-bottom-arrow
{
width:;
height:;
border-bottom:0px solid transparent;
border-left:5px solid transparent;
border-top:10px solid gray;
border-right:5px solid transparent;
display:inline-block;
} .tip-bottom-content
{
height:50px;
line-height:50px;
vertical-align:middle;
background-color:gray;
border-radius:10px;
padding:5px;
padding-right:10px;
}

最后是JS文件:

function leftTip()
{
var length = $(".tip-left").length;
for(var i=0; i<length; i++)
{
var content = $(".tip-left:eq(" + i + ")").text();
$(".tip-left:eq(" + i + ")").text("");
$(".tip-left:eq(" + i + ")").append("<div class='tip-left-arrow'></div>");
$(".tip-left:eq(" + i + ")").append("<div class='tip-left-content'>" + content + "</div>");
} } function rightTip()
{
var length = $(".tip-right").length;
for(var i=0; i<length; i++)
{
var content = $(".tip-right:eq(" + i + ")").text();
$(".tip-right:eq(" + i + ")").text("");
$(".tip-right:eq(" + i + ")").append("<div class='tip-right-content'>" + content + "</div>");
$(".tip-right:eq(" + i + ")").append("<div class='tip-right-arrow'></div>"); }
} function topTip()
{
var length = $(".tip-left").length;
for(var i=0; i<length; i++)
{
var content = $(".tip-top:eq(" + i + ")").text();
$(".tip-top:eq(" + i + ")").text("");
$(".tip-top:eq(" + i + ")").append("<div class='tip-top-arrow'></div>");
$(".tip-top:eq(" + i + ")").append("<div class='tip-top-content'>" + content + "</div>");
$(".tip-top:eq(" + i + ")").css("text-align", "center");
} } function bottomTip()
{
var length = $(".tip-bottom").length;
for(var i=0; i<length; i++)
{
var content = $(".tip-bottom:eq(" + i + ")").text();
$(".tip-bottom:eq(" + i + ")").text("");
$(".tip-bottom:eq(" + i + ")").append("<div class='tip-bottom-content'>" + content + "</div>");
$(".tip-bottom:eq(" + i + ")").append("<div class='tip-bottom-arrow'></div>");
$(".tip-bottom:eq(" + i + ")").css("text-align", "center");
} }

实现需要jquery的支持。

封装tip控件的更多相关文章

  1. .net的自定义JS控件,运用了 面向对象的思想 封装 了 控件(.net自定义控件开发的第一天)

    大家好!我叫刘晶,很高兴你能看到我分享的文章!希望能对你有帮助! 首先我们来看下几个例子 ,就能看到 如何 自定义控件! 业务需求: 制作  一个   属于 自己的    按钮 对象    ,然后 像 ...

  2. 封装BackgroundWorker控件(提供源代码下载,F5即可见效果)

    Demo源码 背景 经常做些小程序或者小DEMO的时候会用到异步,多线程来执行一些比较耗时的工作同时将进度及时进行反馈.我通常会使用位于[ System.ComponentModel]命名空间下的Ba ...

  3. 封装TeeChart控件

    public class MyChart { //字段 private TChart tChart; /// <summary> /// 构造函数,默认不是3D效果 /// </su ...

  4. IP Editor IP控件(对比一下封装IP控件)

    HWND hIpEdit; void __fastcall TForm2::FormCreate(TObject *Sender) { hIpEdit = CreateWindow(WC_IPADDR ...

  5. js封装日历控件

    最终效果 代码实现 <script> $(function () { $(".j-calendar").calendar({ date: '2017-08-03', c ...

  6. 9.2.1 .net framework下的MVC 控件的封装(上)

    在写.net core下mvc控件的编写之前,我先说一下.net framework下我们MVC控件的做法. MVC下控件的写法,主要有如下三种,最后一种是泛型的写法,mvc提供的控件都是基本控件. ...

  7. 控件使用经验-MVP模式+控件封装

    项目背景 几年前参与了一个面向学校的人事管理软件的开发,基于WinForm平台.今天主要想谈一谈其中关于控件的使用经验.这个项目我们大量使用了第三方控件.由于这个产品的生命周期很长,我们在设计时要考虑 ...

  8. 基于wke封装的duilib的webkit浏览器控件,可以c++与js互交,源码及demo下载地址

    转载请说明原出处,谢谢~~ 前些日子用wke内核封装了duilib的webkit浏览器控件,好多群里朋友私聊我希望可以我公布源码,今天把这个控件的源码和使用demo公布.其实这个控件封装起来没什么难度 ...

  9. 将VLC库封装为duilib的万能视频播放控件

    转载请说明出处,谢谢~~ 昨天封装好了基于webkit的浏览器控件,修复了duilib的浏览器功能的不足,而我的仿酷狗播放器项目中不光需要浏览器,同时也需要视频播放功能,也就是完成MV的功能.所以我打 ...

随机推荐

  1. 在linux中使用cmake编译运行cocos2d-x 3.4 projects

    原因: 由于不想在真机环境和 ide中调试环境, 只想在linux端进行 调试和运行, 需要使用cmake对现有的游戏进行编译(cocos2dx-lua 3.4) 修改步骤: 1.修改framewor ...

  2. Xcode 6制作动态及静态Framework

    技术交流新QQ群:414971585 有没有写SDK或者要将一些常用的工具类做成Framework的经历? 你或许自己写脚本完成了这项工作,相信也有很多的人使用 iOS-Universal-Frame ...

  3. cloudera manager安装spark后使用spark shell编写基于scala的world count

    val file = sc.textFile("hdfs://zhcloudil-lcnode04:8020/user/cloudil/wc_spark.txt") val cou ...

  4. Linux达人养成第一季

    Linux简介 一.Linux发展史 二.开源软件简介 三.Linux应用领域 四.Linux学习方法 五.Linux与Windows的不同 六.字符界面的优势 Linux系统安装 一.虚拟机安装 二 ...

  5. web服务器软件集成包问题

    今天下了wampserver,运行错误缺少dll,然后下载apprev也是,最后下了个wampserver 32位了终于没问题了.

  6. opendir函数

    #include<sys/types.h> #include<dirent.h> DIR *dirptr = NULL; struct dirent *entry; dirpt ...

  7. oracle rman恢复数据库 方式恢复到异地数据库

    目的:从某个环境中,获取相关文件,放到异地机器使用rman 恢复.   情况说明:XX系统使用的是oracle数据库,现已从服务器拉下来相关文件,依靠这些文件来早本地的测试机上恢复数据库,方便进行数据 ...

  8. JS 控制CSS样式表

    JS控制CSS所使用的方法: <style> .rule{ display: none; } </style> 你想要改变把他的display属性由none改为inline.  ...

  9. win版本对比

    Win+R 输入:slmgr.vbs -dlv 显示:最为详尽的激活信息,包括:激活ID.安装ID.激活截止日期slmgr.vbs -dli 显示:操作系统版本.部分产品密钥.许可证状态slmgr.v ...

  10. Object类的toString方法

          Object类是所有Java类的祖先.每个类都使用 Object 作为超类.所有对象(包括数组)都实现这个类的方法.在不明确给出超类的情况下,Java会自动把Object作为要定义类的超类 ...