2017年8月

JS判断是否为微信浏览器 js关闭浏览器窗口

function is_weixin(){
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
     } else {
        return false;
    }
}
//如微信浏览器
if(is_weixin()){
    WeixinJSBridge.call('closeWindow');
}else{
    //需处理兼容
    window.close();
}

CSS实现弹窗背景半透明效果

IE:
background-color: rgb(0, 0, 0);
filter: alpha(opacity=20);
非IE:
background-color: rgba(0, 0, 0, 0.2);
兼容:
background-color: rgb(0, 0, 0);
filter: alpha(opacity=20);
background-color: rgba(0, 0, 0, 0.2);

1.弹出框默认状态下是隐藏的,当点击弹出按钮时,显示该弹出框,如下:
<div class="modal" style="display: none;"></div>
2.控制弹出框显示的遮罩层CSS(遮罩整个屏幕,即添加一个灰色背景遮罩层)如下:

.modal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    overflow: hidden;
    outline: 0;
    -webkit-overflow-scrolling: touch;
    background-color: rgb(0, 0, 0);  
    filter: alpha(opacity=60);  
    background-color: rgba(0, 0, 0, 0.6); 
    z-index: 9999;
}

linux安装中文字体

查看已安装中文字体:fc-list :lang=zh
获取字体,如/windows/fonts/获取
mkdir /usr/share/fonts/zh_fonts
cd zh_fonts //复制or下载字体到此处
mkfontscale //yum install -y fontconfig mkfontscale
mkfontdir
fc-cache -fv

PHP判断系统为windows还是linux

函数php_uname()返回所运行的系统信息。php_uname([string $mode]);
$mode可选参数:
'a': 返回所有信息
's': 操作系统的名称,如FreeBSD
'n': 主机的名称,如cnscn.org
'r': 版本名,如5.1.2-RELEASE
'v': 操作系统的版本号
'm': 核心类型,如i386

echo strtoupper(substr(PHP_OS,0,3))==='WIN'?'windows 服务器':'不是 widnows 服务器';
echo DIRECTORY_SEPARATOR=='\\'?'windows 服务器':'不是 widnows 服务器'; //根据分隔符判断
echo PATH_SEPARATOR==';'?'windows 服务器':'不是 widnows 服务器'; //根据PATH分割符判断

linux利用LibreOffice & unoconv 实现word转pdf

libreoffice官网:http://www.libreoffice.org/

wget下载LINUX对应32/64位rpm包
32位 http://ftp.kaist.ac.kr/tdf/libreoffice/stable/5.4.0/rpm/x86/LibreOffice_5.4.0_Linux_x86_rpm.tar.gz
64位 http://ftp.kaist.ac.kr/tdf/libreoffice/stable/5.4.0/rpm/x86_64/LibreOffice_5.4.0_Linux_x86-64_rpm.tar.gz

arm下载:https://www.oracle.com/database/technologies/instant-client/linux-arm-aarch64-downloads.html

- 阅读剩余部分 -

password_hash密码哈希与安全

支持PHP5.5+
项目中大部分加密基于MD5+SALT,事实上password_hash()已经帮我们处理好了加盐。加进去的随机子串通过加密算法自动保存着,成为哈希的一部分。password_verify()会把随机子串从中提取,所以你不必使用另一个数据库来记录这些随机子串,大大简化了计算密码哈希值和验证密码的操作。

- 阅读剩余部分 -

JavaScript手机振动API vibrate

判断浏览器对振动API的支持情况
var supportsVibrate = "vibrate" in navigator;
在window.navigator对象里就只有一个关于振动的API:vibrate。

navigator.vibrate函数可以接受一个数字参数,也可以接受一个数字数组,当使用数组参数时,奇数位的数值是震动秒数,偶数位为等待秒数。

// 振动1秒
navigator.vibrate(1000);

// 振动多次
// 参数分别是震动3秒,等待2秒,然后振动1秒
navigator.vibrate([3000, 2000, 1000]);
如果想停止震动,你只需要向navigator.vibrate方法里传入0,或一个空数组:

// 停止振动
navigator.vibrate(0);
navigator.vibrate([]);

对navigator.vibrate方法的调用并不会引起手机循环振动;当参数是一个数字时,振动之后发生一次,然后就停止下来。当参数是数组时,震动会按数组里的值震动,然后就停止振动。

持续震动

我们可以简单的使用setInterval 和 clearInterval 方法产生让手机持续震动的效果:

var vibrateInterval;

// Starts vibration at passed in level
function startVibrate(duration) {
    navigator.vibrate(duration);
}

// Stops vibration
function stopVibrate() {
    // Clear interval and stop persistent vibrating 
    if(vibrateInterval) clearInterval(vibrateInterval);
    navigator.vibrate(0);
}

// Start persistent vibration at given duration and interval
// Assumes a number value is given
function startPeristentVibrate(duration, interval) {
    vibrateInterval = setInterval(function() {
        startVibrate(duration);
    }, interval);
}