什麼?這是要做前端的節奏嗎?只要公司有需要,我分分鐘變身、前端、美工、UI、交互、後端、資料庫管理員......快速學習、快速響應,快速適應。公司需要我幹啥,我就幹啥,而我存在於公司的意義就是利用所學的東西幫公司解決問題......事實上,如果讓一個人來搞定整個項目包括移動端、PC端等等,那你還不是 ...
什麼?這是要做前端的節奏嗎?只要公司有需要,我分分鐘變身、前端、美工、UI、交互、後端、資料庫管理員......快速學習、快速響應,快速適應。公司需要我幹啥,我就幹啥,而我存在於公司的意義就是利用所學的東西幫公司解決問題......事實上,如果讓一個人來搞定整個項目包括移動端、PC端等等,那你還不是被逼得啥都會。
垂直居中+自動換行
樣式效果如下所示,當文字沒有超出一行時,顯示如“備註信息”,當文字超出一行時,顯示如“維修地點”
HTML代碼如下:
<div class="mui-input-row multi-line"> <div class="box label-right"> <div class="div-leftauto">維修地點</div> <div class="wrap">廣東省深圳市南山區西麗街道桃源路1001號</div> </div> </div>
css樣式如下:
/*不固定高寬div垂直居中的方法:其它頁用*/ .box {width: 100%;height: 40px;border: 1px solid #FFF;display: table;margin-right:5px;} .wrap{display: table-cell; vertical-align: middle; width: 100%;padding: 6px 0px;line-height: 26px;word-wrap: break-word; word-break: break-all;} .mui-input-row .div-leftauto{width:110px; display: inline-block;vertical-align: middle;margin-left:5px;/*padding-top: 8px;vertical-align:top;*/} .mui-input-row.multi-line{height: auto;}
需要註意的是代碼:word-wrap: break-word; word-break: break-all;
如果不加上這代碼的話,當<div class="wrap">中的文字全部是數字或者英文的時候將不會出現自動換行。
文字超出行顯示省略號
如下圖所示:
代碼:
<div style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"> 是文字隨便幾行我是文字隨便幾行我是文字隨便幾行我是文字隨便幾行我是文字隨便幾行我是文字隨便</div>
這裡只支持單行省略號,如果是多行呢?
<div style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 3;overflow: hidden;"> 是文字隨便幾行我是文字隨便幾行我是文字隨便幾行我是文字隨便幾行我是文字隨便幾行我是文字隨便幾行是文字隨便幾行我是文字隨便幾行我是文字隨便幾行我是文字隨便幾行我是文字
隨便幾行我是文字隨便幾行是文字隨便幾行我是文字隨便幾行我是文字隨便幾行我是文字隨便幾行我是文字隨便幾行我是文字隨便幾行 </div>
運行結果如下:
我們看到只顯示了三行,那是因為我-webkit-line-clamp: 3。這裡設置為3.
因使用了WebKit的CSS擴展屬性,該方法適用於WebKit瀏覽器及移動端;
-webkit-line-clamp用來限制在一個塊元素顯示的文本的行數。 為了實現該效果,它需要組合其他的WebKit屬性。
如結合如下屬性:
- display: -webkit-box; 必須結合的屬性 ,將對象作為彈性伸縮盒子模型顯示 。
- -webkit-box-orient 必須結合的屬性 ,設置或檢索伸縮盒對象的子元素的排列方式 。
斜三角形並帶文字效果
效果如下圖所示:
HTML如下:
<div class="font-topright"">待完工</div> <div class="triangle-topright mui-badge-orange"></div> <div class="font-seal">待料</div>
CSS代碼(註意樣式的命名,不要搞神馬大小寫,建議用-或者_連接,統一使用小寫):
.font-seal { font-size: 12px;z-index: 2;position: absolute;right:14px;top: 35px; border: 1px solid #F73A3C; transform: rotate(45deg);width: 53px;line-height: 20px;text-align: center;color: #F73A3C;font-weight: bold; } /** * 三角形氣泡 */ .triangle-topright { width: 0;height: 0;border-top: 44px solid #FD9D2D;border-left: 2rem solid transparent; } .font-topright { font-size: 12px;z-index: 2;position: absolute;right: -4px;top: -2px; transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg); -ms-transform: rotate(45deg);-o-transform: rotate(45deg);width: 43px;line-height: 43px;text-align: center;color: #FFFFFF; } .mui-badge.mui-badge-orange{background-color:#FC9C2D;color:#FFFFFF;}
時間軸效果
時間軸設計的難點在於所有的節點都是動態渲染的,最新的節點又和其它節點的樣式不一致,節點的顯示位置比較難控制,還有就是節點之間的連線必須恰到好處的把各個節點連接起來。
最終渲染的HTML代碼:
<body class="mui-ios mui-ios-11 mui-ios-11-0"> <div id="app" class="mui-content" style="background-color: rgb(255, 255, 255);"> <div class="empty-container" style="display: none;"> <div class="nodata-info">暫無相關內容</div> <div class="nodata-icon"> <span class="mui-icon iconfont icon-wuneirong"></span> </div> </div> <section id="cd-timeline" class="cd-container" style=""> <div class="cd-timeline-block"> <div class="cd-timeline-img cd-picture"></div> <div class="cd-timeline-content"> <div>用戶4,工單結束</div> <div class="cd-date">2018-05-22 14:33:58</div> </div> </div> <div class="cd-timeline-block"> <div class="cd-timeline-img cd-movie"></div> <div class="cd-timeline-content"> <div>用戶4,工作人員到場簽到</div> <div class="cd-date">2018-05-22 14:33:44</div> </div> </div><div class="cd-timeline-block"> <div class="cd-timeline-img cd-movie"></div> <div class="cd-timeline-content"> <div>用戶4,分配工作人員</div> <div class="cd-date">2018-05-22 14:33:34</div> </div> </div> <div class="cd-timeline-block"> <div class="cd-timeline-img cd-movie"></div> <div class="cd-timeline-content"><div>用戶4,提交報修單</div> <div class="cd-date">2018-05-21 18:06:44</div></div> </div> </section> </div> </body>
CSS樣式timeline.css
[v-cloak] {display: none !important;}/*visibility: hidden;*/ /* -------------------------------- Primary style -------------------------------- */ /*html{background-color: #FFFFFF;}*/ .mui-bar{background-color: #449DED;} .mui-bar-nav .mui-icon {color: #FFFFFF;} .mui-title {color: #fff;} *, *:after, *:before { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } img {max-width: 100%;} /* -------------------------------- Modules - reusable parts of our design -------------------------------- */ .cd-container { /* this class is used to give a max-width to the element it is applied to, and center it horizontally when it reaches that max-width */ width: 100%;max-width: 1170px;margin: 0; } .cd-container::after { /* clearfix */ content: '';display: table;clear: both; } /* -------------------------------- Main components -------------------------------- */ #cd-timeline { position: relative;padding: 0;margin-top: 0;margin-bottom: 1em; } /*#cd-timeline::before { content: '';position: absolute;top: 0;left: 18px; height: 80%;width: 1px;background: #C3E3FF;top:20px; }*/ .cd-timeline-block:before{ content: '';position: absolute;height: 67px;width: 1px; background: #C3E3FF;left: 25px;bottom: -28px; } .cd-timeline-block:first-child:before{ top: 28px; } .cd-timeline-block:last-child:before{ height: 0px; } #cd-timeline::after { height: 0px; } @media only screen and (min-width: 1170px) { #cd-timeline { margin-top: 3em;margin-bottom: 3em; } #cd-timeline::before { left: 50%;margin-left: -2px;} } .cd-timeline-block { position: relative;margin: 2px 0 0 0; } .cd-timeline-block:after { content: "";display: table;clear: both; } .cd-timeline-block:first-child { margin-top: 0; } .cd-timeline-block:last-child { margin-bottom: 0; } @media only screen and (min-width: 1170px) { .cd-timeline-block { margin: 4em 0; } .cd-timeline-block:first-child { margin-top: 0; } .cd-timeline-block:last-child { margin-bottom: 0; } } .cd-timeline-img { position: absolute;top: 0;left: 0;width: 16px;height: 16px;border-radius: 50%; margin-top: 10px;box-shadow: 0 0 0 5px #DDEEFE;/*inset 0 2px 0 #60B2FB, 0 3px 0 5px #DDEEFE;*/ } .cd-timeline-img img { display: block;width: 24px;height: 24px; position: relative;left: 50%;top: 50%;margin-left: -12px;margin-top: -12px; } .cd-timeline-img.cd-picture { background: #60B3FC; margin-left: 17px;margin-top: 25px; } .cd-timeline-img.cd-movie { background: #60B2FB; left: 21px;width: 10px;height: 10px;box-shadow:none;top:16px; } .cd-timeline-img.cd-location { background: #f0ca45; } @media only screen and (min-width: 1170px) { .cd-timeline-img { width: 60px;height: 60px;left: 50%;margin-left: -30px; /* Force Hardware Acceleration in WebKit */ -webkit-transform: translateZ(0);-webkit-backface-visibility: hidden; } .cssanimations .cd-timeline-img.is-hidden { visibility: hidden; } .cssanimations .cd-timeline-img.bounce-in { visibility: visible;-webkit-animation: cd-bounce-1 0.6s; -moz-animation: cd-bounce-1 0.6s; animation: cd-bounce-1 0.6s; } } .cd-timeline-content { position: relative;margin-left: 50px;background: white; border-radius: 0;padding: 0.4em;box-shadow: 0 1px 0 #d7e4ed; } .cd-timeline-content:after { content: "";display: table;clear: both; } .cd-timeline-content h2 { color: #303e49; } .cd-timeline-content p, .cd-timeline-content .cd-read-more, .cd-timeline-content .cd-date { font-size: 13px;font-size: 0.8125rem; } .cd-timeline-content .cd-read-more, .cd-timeline-content .cd-date { display: inline-block; } .cd-timeline-content p { margin: 1em 0;line-height: 1.6; } .cd-timeline-content .cd-read-more { float: right;padding: .8em 1em; background: #acb7c0;color: white;border-radius: 0.25em; } .no-touch .cd-timeline-content .cd-read-more:hover { background-color: #bac4cb; } a.cd-read-more:hover{text-decoration:none; background-color: #424242; } .cd-timeline-content .cd-date { float: left;padding: .4em 0;color: #A3A3A3; } .cd-timeline-content::before { content: '';position: absolute;top: 9px;right: 100%;height: 0;width: 0; border: 7px solid transparent;border-right: 7px solid white; } @media only screen and (min-width: 768px) { .cd-timeline-content h2 { font-size: 20px;font-size: 1.25rem; } .cd-timeline-content p { font-size: 16px;font-size: 1rem; } .cd-timeline-content .cd-read-more, .cd-timeline-content .cd-date { font-size: 14px;font-size: 0.875rem; } } @media only screen and (min-width: 1170px) { .cd-timeline-content { margin-left: 0;padding: 1.6em; width: 45%; } .cd-timeline-content::before { top: 24px;left: 100%;border-color: transparent;border-left-color: white; } .cd-timeline-content .cd-read-more { float: left; } .cd-timeline-content .cd-date { position: absolute;width: 100%;left: 122%;top: 6px;font-size: 16px;font-size: 1rem; } .cd-timeline-block:nth-child(even) .cd-timeline-content { float: right; } .cd-timeline-block:nth-child(even) .cd-timeline-content::before { top: 24px;left: auto;right: 100%;border-color: transparent;border-right-color: white; } .cd-timeline-block:nth-child(even) .cd-timeline-content .cd-read-more { float: right; } .cd-timeline-block:nth-child(even) .cd-timeline-content .cd-date { left: auto;right: 122%;text-align: right; } .cssanimations .cd-timeline-content.is-hidden { visibility: hidden; } .cssanimations .cd-timeline-content.bounce-in { visibility: visible;-webkit-animation: cd-bounce-2 0.6s; -moz-animation: cd-bounce-2 0.6s;animation: cd-bounce-2 0.6s; } } @media only screen and (min-width: 1170px) { /* inverse bounce effect on even content blocks */ .cssanimations .cd-timeline-block:nth-child(even) .cd-timeline-content.bounce-in { -webkit-animation: cd-bounce-2-inverse 0.6s; -moz-animation: cd-bounce-2-inverse 0.6s; animation: cd-bounce-2-inverse 0.6s; } } .cd-timeline-content div{height: 21px;line-height: 21px;} .cd-timeline-content div:first-child{ color: #6DB6FE;font-size: 14px;line-height: 25px; } .cd-timeline-content div:last-child{line-height: 18px;} /*為空*/ .empty-container{text-align:center;padding: 30% 0;background-color:#F5F5F5;overflow:hidden;height: 100%;position: fixed;width: 100%;} .nodata-info{color:#C7C3C2;} .nodata-icon{color:#C7C3C2;margin-top:25px;} .nodata-icon .mui-icon{font-size:120px;}View Code
我這裡原來是使用了vue.js,理論上支持N個時間節點,原代碼如下:
<div id="app" class="mui-content" style="background-color: #FFFFFF;"> <div v-show="isEmptyData" class="empty-container" v-cloak> <div class="nodata-info">暫無相關內容</div> <div class="nodata-icon"><span class="mui-icon iconfont icon-wuneirong"></span></div> </div> <section v-show="list.length>0" id="cd-timeline" class="cd-container" v-cloak> <div v-for="(item,index) in list" class="cd-timeline-block"> <div class="cd-timeline-img" v-bind:class="[index==0?'cd-picture':'cd-movie']"></div> <div class="cd-timeline-content"> <div v-text="item.text"></div> <div class="cd-date" v-text="item.t"></div> </div> </div> </section> </div>
js代碼:
var vm = new Vue({ el: '#app', data: { isEmptyData:false, list: [] }, mounted: function () { mui.init(); this.list = [{ "text": "用戶4,工單結束", "t": "2018-05-22 14:33:58" }, { "text": "用戶4,工作人員到場簽到", "t": "2018-05-22 14:33:44" },
{ "text": "用戶4,分配工作人員", "t": "2018-05-22 14:33:34" }, { "text": "用戶4,提交報修單", "t": "2018-05-21 18:06:44" }];
}});
MUI是非常輕量級的移動前端框架,而vue.js也是極簡而優雅的mvvm框架,所以他們兩合在一起使用實在是太方便了,不過他們兩一起使用的同時會存在許多坑,若要避開這些坑,你需要知道MUI和vue.js他們的運行機制,其實也就是Dom操作、mui的生命周期同數據驅動、vue.js生命周期它們之間區別。