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

尖角的实现很简单的,一般都是通过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控件的更多相关文章
- .net的自定义JS控件,运用了 面向对象的思想 封装 了 控件(.net自定义控件开发的第一天)
大家好!我叫刘晶,很高兴你能看到我分享的文章!希望能对你有帮助! 首先我们来看下几个例子 ,就能看到 如何 自定义控件! 业务需求: 制作 一个 属于 自己的 按钮 对象 ,然后 像 ...
- 封装BackgroundWorker控件(提供源代码下载,F5即可见效果)
Demo源码 背景 经常做些小程序或者小DEMO的时候会用到异步,多线程来执行一些比较耗时的工作同时将进度及时进行反馈.我通常会使用位于[ System.ComponentModel]命名空间下的Ba ...
- 封装TeeChart控件
public class MyChart { //字段 private TChart tChart; /// <summary> /// 构造函数,默认不是3D效果 /// </su ...
- IP Editor IP控件(对比一下封装IP控件)
HWND hIpEdit; void __fastcall TForm2::FormCreate(TObject *Sender) { hIpEdit = CreateWindow(WC_IPADDR ...
- js封装日历控件
最终效果 代码实现 <script> $(function () { $(".j-calendar").calendar({ date: '2017-08-03', c ...
- 9.2.1 .net framework下的MVC 控件的封装(上)
在写.net core下mvc控件的编写之前,我先说一下.net framework下我们MVC控件的做法. MVC下控件的写法,主要有如下三种,最后一种是泛型的写法,mvc提供的控件都是基本控件. ...
- 控件使用经验-MVP模式+控件封装
项目背景 几年前参与了一个面向学校的人事管理软件的开发,基于WinForm平台.今天主要想谈一谈其中关于控件的使用经验.这个项目我们大量使用了第三方控件.由于这个产品的生命周期很长,我们在设计时要考虑 ...
- 基于wke封装的duilib的webkit浏览器控件,可以c++与js互交,源码及demo下载地址
转载请说明原出处,谢谢~~ 前些日子用wke内核封装了duilib的webkit浏览器控件,好多群里朋友私聊我希望可以我公布源码,今天把这个控件的源码和使用demo公布.其实这个控件封装起来没什么难度 ...
- 将VLC库封装为duilib的万能视频播放控件
转载请说明出处,谢谢~~ 昨天封装好了基于webkit的浏览器控件,修复了duilib的浏览器功能的不足,而我的仿酷狗播放器项目中不光需要浏览器,同时也需要视频播放功能,也就是完成MV的功能.所以我打 ...
随机推荐
- Perl的基本语法(转)
(原文来自:http://www.jb51.net/shouce/perl.htm)
- 特别实用而且功能强大的attributedText属性
UILabel *sendNameLB = [[UILabel alloc]initWithFrame:CGRectMake(, , , )]; NSString * string = @" ...
- php日历
一.计算数据 1.new一个Calendar类 2.初始化两个下拉框中的数据,年份与月份 3.初始化要搜索的年份和月份 4.计算得出日历中每一天的数据信息,包括css.天数 <?php requ ...
- java内存分配--引用
栈内存 对象地址 堆内存 存放属性 public class TestDemo{ public static void main(String args[]){ Person perA =new ...
- HDU 1403-Longest Common Substring (后缀数组)
Description Given two strings, you have to tell the length of the Longest Common Substring of them. ...
- js问题
1.原型链问题 1.js中万物皆对象,但对象也分为普通对象和函数对象,Object,Function都是js自带的函数对象,凡是通过 new Function() 创建的对象都是函数对象,其他的都是普 ...
- Java中的构造代码块
代码块 ----a静态代码块 ----b构造代码块 ----c普通代码块 执行顺序:(优先级从高到低.)静态代码块>mian方法>构造代码块>构造方法. a.静态代码块: 静态代码块 ...
- HashMap 与 HashTable的区别
1.HashTable的方法是同步的,HashMap未经同步,所以在多线程场合要手动同步HashMap这个区别就像Vector和ArrayList一样.可以用synchronized实现HashMap ...
- tomcat集群
apache整合tomcat部署集群 http://www.cnblogs.com/God-froest/p/apache_tomcat.html 今天看到"基于apache的tomcat负 ...
- c#执行bat批处理文件,并通过线程将结果显示在控件中
核心代码如下: Process p = new Process(); p.StartInfo.FileName = filePath; p.StartInfo.UseShellExecute = fa ...