1.使用css的content属性attr抓取资料
//需求 鼠标悬停的时候出现文字提示 如下图所示:1
2
3<div data-msg="Open this file in Github Desktop">
``hover
</div>
1 | div{ |
2.使用 :not() 去除导航上不需要的属性1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16<ul class="nav">
<li>a</li>
<li>b</li>
<li>c</li>
<li>d</li>
<li>e</li>
</ul>
li{
list-style:none;
margin-bottom:10px;
display:inline-block;
}
ul > li:not(:last-child)::after {
content: ",";
}
a, b, c, d, e
3.两端对齐1
text-align-last: justify;
4.移动web页面支持弹性滚动
在IOS机型中,非body元素的滚动条会非常不流畅,又不想用JS模拟滚动条。1
2
3
4
5
6body{
-webkit-overflow-scrolling: touch; /* ios5+ */
}
ele{
overflow:auto;
}
JavaScript编程黑科技
匿名函数自执行1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20( function() {}() );
( function() {} )();
[ function() {}() ];
~ function() {}();
! function() {}();
+ function() {}();
- function() {}();
delete function() {}();
typeof function() {}();
void function() {}();
new function() {}();
new function() {};
var f = function() {}();
1, function() {}();
1 ^ function() {}();
1 > function() {}();
取整1
2
3var a = ~~2.33
var b= 2.33 | 0
var c= 2.33 >> 0
格式化金钱1
2
3var test1 = '1234567890'
var format = test1.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
console.log(format) // 1,234,567,890