这些天练习UI组件的编写,顺便模仿一个h5版本的pre标签收缩展开的效果组件:

兼容ie8、9,谷歌,火狐;

图片效果如下:

demo.html代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="js/cnExpandPanel/cnExpandPanel.css" rel="stylesheet"/>
<style>
/*可以更改这两个参数来调整内容高度以及放大后的最小高度*/
.banner-expand{
height:200px;
min-height:200px;
        }
        .banner-expand.on {
min-height:200px;
}
/*可以设置内容宽度,以及其他css样式*/
.banner{
width:500px;
}
</style>
</head>
<body style="background-color:#6C6B6B;margin:0;padding:0">
<div class="banner">
<pre class="banner-expand">
onabort, onbeforeunload, onblur, onchange, onclick, oncontextmenu,
ondblclick, ondrag, ondragend, ondragenter, ondragleave, ondragover,
ondragstart, ondrop, onerror, onfocus, onkeydown, onkeypress, onkeyup,
onload, onmessage, onmousedown, onmousemove, onmouseover, onmouseout,
onmouseup, onmousewheel, onresize, onscroll, onselect, onsubmit, onunload
onabort, onbeforeunload, onblur, onchange, onclick, oncontextmenu,
ondblclick, ondrag, ondragend, ondragenter, ondragleave, ondragover,
ondragstart, ondrop, onerror, onfocus, onkeydown, onkeypress, onkeyup,
onload, onmessage, onmousedown, onmousemove, onmouseover, onmouseout,
onmouseup, onmousewheel, onresize, onscroll, onselect, onsubmit, onunload
onabort, onbeforeunload, onblur, onchange, onclick, oncontextmenu,
ondblclick, ondrag, ondragend, ondragenter, ondragleave, ondragover,
ondragstart, ondrop, onerror, onfocus, onkeydown, onkeypress, onkeyup,
onload, onmessage, onmousedown, onmousemove, onmouseover, onmouseout,
onmouseup, onmousewheel, onresize, onscroll, onselect, onsubmit, onunload
onabort, onbeforeunload, onblur, onchange, onclick, oncontextmenu,
ondblclick, ondrag, ondragend, ondragenter, ondragleave, ondragover,
ondragstart, ondrop, onerror, onfocus, onkeydown, onkeypress, onkeyup,
onload, onmessage, onmousedown, onmousemove, onmouseover, onmouseout,
onmouseup, onmousewheel, onresize, onscroll, onselect, onsubmit, onunload
onabort, onbeforeunload, onblur, onchange, onclick, oncontextmenu,
ondblclick, ondrag, ondragend, ondragenter, ondragleave, ondragover,
ondragstart, ondrop, onerror, onfocus, onkeydown, onkeypress, onkeyup,
onload, onmessage, onmousedown, onmousemove, onmouseover, onmouseout,
onmouseup, onmousewheel, onresize, onscroll, onselect, onsubmit, onunload
onabort, onbeforeunload, onblur, onchange, onclick, oncontextmenu,
ondblclick, ondrag, ondragend, ondragenter, ondragleave, ondragover,
ondragstart, ondrop, onerror, onfocus, onkeydown, onkeypress, onkeyup,
onload, onmessage, onmousedown, onmousemove, onmouseover, onmouseout,
onmouseup, onmousewheel, onresize, onscroll, onselect, onsubmit, onunload
</pre>
<div class="banner-footer J_BannerFooter">
<i class="icon-chevron-down icon-white J_ExpandDown i-show"></i>
<i class="icon-chevron-up icon-white J_ExpandUp i-hid"></i>
</div>
</div>
<script src="js/jquery-1.8.3.min.js"></script>
<script src="js/cnExpandPanel/cnExpandPanel.js"></script>
<script>
cnExpandPanel.initDom();
</script>
</body>
</html>

cnExpandPanel.css代码:

/* 该组件依赖于bootstrap2的图标,如果引用了bootstrap2的css文件,则该段css可以删掉 start */
.icon-chevron-down {
background-position: -313px -119px;
}
.icon-chevron-up {
background-position: -288px -120px;
}
.icon-white{
width: 14px;
height: 14px;
margin-top: 1px;
*margin-right: .3em;
line-height: 14px;
vertical-align: text-top;
background-image: url("img/glyphicons-halflings-white.png");
background-repeat: no-repeat;
}
/* 该组件依赖于bootstrap2的图标,如果引用了bootstrap2的css文件,则该段css可以删掉 end */
.banner {
position: relative;
}
.banner-expand {
white-space: pre;
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
display: block;
margin: 0 0 10px;
line-height: 1.42857143;
word-break: break-all;
background: rgba(0,0,0,0.17);
border:0 #2b2b2b;
border-radius:;
color: #5ca258;
font-family: Monaco,Consolas,"Lucida Console",monospace;
font-size: 12px;
min-height: 100px;
padding: 10px 20px;
transition: height .2s ease;
box-shadow: inset 0 0 1px rgba(0,0,0,0.71);
height: 200px;
overflow: hidden;
position: relative;
}
.banner-expand.on {
overflow: visible;
height:auto;
min-height:200px;
}
.banner-footer{
bottom:;
text-align:center;
background-color: #1d1d1d;
background: -moz-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.59) 90%,rgba(0,0,0,0.65) 100%);
background: -webkit-gradient(linear,left top,left bottom,color-stop(0%,rgba(0,0,0,0)),color-stop(90%,rgba(0,0,0,0.59)),color-stop(100%,rgba(0,0,0,0.65)));
background: -webkit-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.59) 90%,rgba(0,0,0,0.65) 100%);
background: -o-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.59) 90%,rgba(0,0,0,0.65) 100%);
background: -ms-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.59) 90%,rgba(0,0,0,0.65) 100%);
background: linear-gradient(to bottom,rgba(0,0,0,0) 0,rgba(0,0,0,0.59) 90%,rgba(0,0,0,0.65) 100%);
filter:alpha(opacity=0,finishOpacity=80,style=1,startx=0,startY=0,finishx=0,finishY=150);
-ms-filter:alpha(opacity=0,finishOpacity=80,style=1,startx=0,startY=0,finishx=0,finishY=150);
cursor: pointer;
position:absolute;
width:100%;
}
.banner-footer:hover{
background: rgba(0,0,0,0.74);
filter:none;
-ms-filter:none;
}
.i-show{
display:inline-block;
}
.i-hid{
display:none;
}

cnExpandPanel.js代码:

/**
* Created by rise_horizon on 2015/4/3.
* 依赖于jquery语法
*/
var cnExpandPanel = (function($){
function _troggleDom($this) {
var $J_ExpandUp = $this.find(".J_ExpandUp");
var $J_ExpandDown = $this.find(".J_ExpandDown");
if($J_ExpandDown.css("display") != "none") {
_collapseDom($J_ExpandUp, $J_ExpandDown, $this);
} else {
_expandDom($J_ExpandUp, $J_ExpandDown, $this);
}
}
function _collapseDom($J_ExpandUp, $J_ExpandDown, $this) {
$this.siblings("pre").addClass("on");
$J_ExpandUp.removeClass("i-hid");
$J_ExpandUp.addClass("i-show");
$J_ExpandDown.removeClass("i-show");
$J_ExpandDown.addClass("i-hid");
}
function _expandDom($J_ExpandUp, $J_ExpandDown, $this) {
$this.siblings("pre").removeClass("on");
$J_ExpandDown.removeClass("i-hid");
$J_ExpandDown.addClass("i-show");
$J_ExpandUp.removeClass("i-show");
$J_ExpandUp.addClass("i-hid");
}
function initDom() {
$(".J_BannerFooter").on("click",function(){
var $this = $(this);
_troggleDom($this);
});
}
return {initDom : initDom}
})(jQuery);

代码都在这里了,两张img图片是bootstrap2里的,可以自行找到,也可下载上传到csdn网站的实例,地址是http://download.csdn.net/detail/tv151579/8576589

创建一个pre标签展开折叠的UI组件(原创)的更多相关文章

  1. new Option() 创建一个option标签

    //add() 方法用于向 <select> 添加一个 <option> 元素. //new Option() 创建一个option标签 school.add(new Opti ...

  2. js如何动态创建一个新的标签

    var DS; DS = CallIVRAjaxClass.GetBranchCallCount().value; var obj = {}; obj.branch = "_branch&q ...

  3. 聊一聊HTML <pre>标签

    聊一聊HTML <pre>标签 我们经常会在要保持文本格式的时候使用pre标签,比如当我们要展示源代码的时候,只要放一个pre标签,然后把源代码直接复制,粘贴,然后在页面上就可以保持好格式 ...

  4. HTML中pre标签的用法

    我们经常会在要保持文本格式的时候使用pre标签,比如当我们要展示源代码的时候,只要放一个pre标签,然后把源代码直接复制,粘贴,然后在页面上就可以保持好格式.不会像放在其它标签里那样,把换行和空格都自 ...

  5. 用Backbone.js创建一个联系人管理系统(五)

    原文: Build a Contacts Manager Using Backbone.js: Part 5 这是这系列教程最后一部分了. 之前所有的增删改都在前端完成. 这部分我们要把Contact ...

  6. 16款优秀的Vue UI组件库推荐

    16款优秀的Vue UI组件库推荐 Vue 是一个轻巧.高性能.可组件化的MVVM库,API简洁明了,上手快.从Vue推出以来,得到众多Web开发者的认可.在公司的Web前端项目开发中,多个项目采用基 ...

  7. [转载]前端——实用UI组件库

    https://www.cnblogs.com/xuepei/p/7920888.html Angular UI 组件 ngx-bootstrap 是一套Bootstrap 组件 官网:https:/ ...

  8. 强烈推荐优秀的Vue UI组件库

    Vue 是一个轻巧.高性能.可组件化的MVVM库,API简洁明了,上手快.从Vue推出以来,得到众多Web开发者的认可.在公司的Web前端项目开发中,多个项目采用基于Vue的UI组件框架开发,并投入正 ...

  9. ui组件库

    基于Vue的Quasar Framework 中文网 http://www.quasarchs.com/ quasarframework/quasar: Quasar Frameworkhttps:/ ...

随机推荐

  1. [xsy2913]enos

    题意:一棵树,点有$0,1,2$三种颜色,支持路径修改颜色和查询点所在同色连通块的大小 lcm太可怕了,于是去问了sk,得到一个优质做法 考虑lct维护子树信息,$vs_{x,i}$为$x$的虚儿子中 ...

  2. [HDU6203]ping ping ping

    题目大意: 给你一棵树,其中有一些点是坏掉的.告诉你k个点对表示这两个点的路径上至少有1个点是坏掉的.问整棵树上至少有多少点是坏的. 思路: 贪心. 找出每组点对的LCA,对所有点对按照LCA的深度排 ...

  3. PYQT窗口风格

    setWindowFlags(Qt.WindowFlags)函数,Qt.WindowFlags类如下: 1.窗口类型 Qt.Qt.Widget#插件默认窗口,有最小化.最大化.关闭按钮 Qt.Qt.W ...

  4. Codeforces Round #283 (Div. 2) C. Removing Columns 暴力

    C. Removing Columns time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. 读书笔记_Effective_C++_条款三十八:通过复合塑模出has-a或者is-implemented-in-terms-of

    如果说public是一种is-a的关系的话,那么复合就是has-a的关系.直观来说,复合就是在一个类中采用其他类的对象作为自身的成员变量,可以举个例子,像下面这样: class Person { pr ...

  6. Linux常用命令&定位生产报错日志

    1. cd / 到根目录下 2. cd .. 返回上层目录 3.ls 显示当前目录有哪些文件 4. pwd 显示当前目录 5. ps -ef|grep tomcat7 查看当前运行进程 6. kill ...

  7. HDU 3726 Graph and Queries (离线处理+splay tree)

    Graph and Queries Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  8. Oracle 12c on Solaris 10 安装文档

    http://www.orasql.com/blog/archives/2013/08/20/12c_solaris.htm

  9. 如何在windows server 2008上配置NLB群集

    参考:http://zlwdouhao.blog.51cto.com/731028/781828 前些天写了一篇关于NLB群集模式多播和单播的简单介绍.那么下面我们一起来探讨一下,如何在windows ...

  10. linux列出一个目录及其子目录下面的某种类型的文件

    linux列出一个目录及其子目录下面的某种类型的文件 作者:smarteng ⁄ 时间:2009年07月09日 ⁄ 分类: Linux命令 ⁄ 评论:0 怎么样把,一个目录及其所有的子目录下面的某种类 ...