请问这种写法对写页面速度有实际上的提升吗?
问题描述:
最近在搭建一个页面重构库,目标很简单,就是加快写页面的速度。现在正在完善mixin这一块,就是写一些常用的css组合。这一块的所有代码如下:
/** * @module 通用-mixin * @author Rufer <547719886@qq.com> * @license GPL-3.0+ * @copyright © 2017 https://github.com/Miller547719886 */ // 鼠标悬浮效果(ie9+) @mixin hover($t: 0.2s) { transition: background-color t,height t,opacity t; -webkit-transition: background-color t,height t,opacity t; } //文字溢出省略(width为字符串,如'100px'或'100%') @mixin ellipsis($width: auto) { width: width; white-space: nowrap; overflow: hidden; text-overflow: hidden; } @mixin ta-c() { text-align: center; } @mixin va-m() { vertical-align: middle; } @mixin td-lt() { text-decoration: line-through; } @mixin bg($url:'https://avatars3.githubusercontent.com/u/16618956?v=3&u=aebaf068c5e16f46cffe384e6e1a8d471b1a73dc&s=400',$size:'100% auto') { background-image: url($url); background-size: $size; background-repeat: no-repeat; background-position: center; } @mixin va-m() { vertical-align: middle; } @mixin relat-pt($pt: 0) { position: relative; padding-top: $pt; } @mixin relat-pl($pl: 0) { position: relative; padding-left: $pl; } @mixin relat-pb($pb: 0) { position: relative; padding-bottom: $pb; } @mixin relat-pr($pr: 0) { position: relative; padding-right: $pr; } @mixin relat-plr($plr: 0) { position: relative; padding-left: $plr; padding-right: $plr; } @mixin relat-ptb($ptb: 0) { position: relative; padding-top: $ptb; padding-bottom: $ptb; } @mixin abs-l($w:0,$h:100%) { position: absolute; width: $w; height: $h; top: 0; left: 0; } @mixin abs-r($w:0,$h:100%) { position: absolute; width: $w; height: $h; top: 0; right: 0; } @mixin abs-t($h:0,$w:100%) { position: absolute; width: $w; height: $h; top: 0; left: 0; } @mixin abs-t($h:0,$w:100%) { position: absolute; width: $w; height: $h; bottom: 0; left: 0; } @mixin pop($bg:rgba(0,0,0,.5)) { position: fixed; width: 100%; height: 100%; z-index: 999; background-color: $bg; } @mixin center($w:100%,$h:100%) { position: absolute; top: 50%; left: 50%; width: $w; height: $h; margin-left: - ($w / 2); margin-top: - ($h / 2); } @mixin pic-fill() { display: block; width: 100%; height: 100%; } @mixin pic-auto() { display: block; max-width: 100%; max-height: 100%; margin: 0 auto; } @mixin icon($w:20px,$h:20px,$url:'https://avatars3.githubusercontent.com/u/16618956?v=3&u=aebaf068c5e16f46cffe384e6e1a8d471b1a73dc&s=400',$size:'100% auto') { display: inline-block; width: $w; height: $h; background-image: url($url); background-size: $w $h; background-repeat: no-repeat; background-position: center; } // @mixin bordert-s1($c:#e2e2e2) { // border-top: 1px solid $c; // } // @mixin borderr-s1($c:#e2e2e2) { // border-right: 1px solid $c; // } // @mixin borderb-s1($c:#e2e2e2) { // border-bottom: 1px solid $c; // } // @mixin borderl-s1($c:#e2e2e2) { // border-left: 1px solid $c; // } // @mixin borderl-d1($c:#e2e2e2) { // border-left: 1px dashed $c; // } //注意:此mixin会覆盖元素的after伪类! @mixin mid-refs() { &:after { content: ""; display: inline-block; width: 0; height: 100%; vertical-align: middle; overflow: hidden; } } @mixin box-shadow($bs:0px 2px 10px #cdcdcd) { box-shadow: $bs; -webkit-box-shadow: $bs; -o-box-shadow: $bs; -moz-box-shadow: $bs; } @mixin line-height($h:28px) { display: inline-block; height: $h; line-height: $h; }
来此提问的目的一是想确认我做这件事带来的收益是否是长期的,稳定的,二是如果一的答案是肯定的,各位是否能帮助我提供更多的css组合得以完善。谢谢!
第 1 个答案:
这种事情做得好的话收益当然是长期稳定的,不过要引入自己写的库,为啥不用现有的库呢?除了自己比较熟悉以外,最好有其他方面的优势,比如特别适合公司业务啊之类,不然和别人合作的情况下,用通用库更能加速磨合和减少沟通学习成本。
更加完善方面,依然是通用合作方面的考虑,我想名字可以起得直白一些,比如abs-t,relat-plr,va-m 之类的缩写最好一目了然为好,省去查文档的时间比少打几个字划算多了。
最后一个马上可以改变的地方,你的 abs-t 写了两次,如果我的理解没错,你应该是想写, abs-b 的,打错字了。
父元素div,默认样式已经清除了,但是父元素div跟img元素的0.2px误差从何而来求大神指点,十分感谢