2017-7-6日记

1.逻辑代替if:

zepto源码中

window.$ === undefined && (window.$ = Zepto)
day && alert('today is sunday!');

2.关于css的恶作剧(鼠标消失)

*{
    cursor:none!important;
}

3.简单的文字模糊效果

p{
    color:transparent;
    text-shadow:#333 0 0 5px;
}

  达到将文字模糊化处理的目的,出来的效果有点类似于使用PS滤镜.

4.创建长宽比固定的元素

如果一个元素设置了宽度,这时候再去设置它的padding-bottom的值为百分比,其padding-bottom所取百分比是根据元素自身宽度来进行计算的,也就是说,如果一个元素的设置了宽度100px,此时再设置其padding-bottom:100%,则其为一个宽高皆为100px的正方形元素.

5.生成随机字符串

function generateRandomAlphaNum (len) {
    var rdmString = '';
    for(; rdmString.length < len;rdmString += Math.random().toString(36).substr(2));
    return rdmString.substr(0,len);
}

这里需要解释一下toString()的用法,其不仅仅转化成字符串,其还可以接受一个参数作为基数,这个基数从2到36封顶,如果不指定,默认基数是10进制的.

6.整数操作,向下取整的另类方法

3.5 | 0 == 3;   //true
~~3.5 == 3;   //true

7.快速将一个值转化为布尔值

!!window === true;  //true

8.不声明第三个变量的值交换(真的六)

var a=1,b=2;
a = [b,b=a][0];

 

posted @ 2017-07-06 16:49  上山打松鼠  阅读(147)  评论(0编辑  收藏  举报