墨惜 发布的文章

//浏览器适用       
contextClass = window.AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext ||
    window.msAudioContext;
try {
    var context = new contextClass();
    var source = null;
    var audioBuffer = null;

    function stopSound() {
        if (source) {
            source.stop(musics); //立即停止
        }
    }

    function playSound() {
        source = context.createBufferSource();
        source.buffer = audioBuffer;
        source.loop = true;
        source.connect(context.destination);
        source.start(0); //立即播放    
    }

    function initSound(arrayBuffer) {
        context.decodeAudioData(arrayBuffer, function(buffer) { //解码成功时的回调函数
            audioBuffer = buffer;
            playSound();
        }, function(e) { //解码出错时的回调函数
            console.log('404', e);
        });
    }

    function loadAudioFile(url) {
        var xhr = new XMLHttpRequest(); //通过XHR下载音频文件
        xhr.open('GET', url, true);
        xhr.responseType = 'arraybuffer';
        xhr.onload = function(e) { //下载完成
            initSound(this.response);
        };
        xhr.send();
    }
    //这里用来存储背景音乐的路径
    loadAudioFile('audio/music.flac');
} catch (e) {
    console.log('无法找到音乐!');
}

直接在console输入以下代码,步骤如下:

打开F12点击Console
输入(function(){}).constructor === Function,回车;
如果返回的是true,继续输入Function.prototype.constructor = function(){},并回车;
切换回sources选项卡,点击继续执行,无限debugger的问题就解决了
注意:如果第二步返回的是false,则此方法不可用。

(function(){}).constructor === Function
Function.prototype.constructor = function(){}

这个代码放在PC模板的代码里面

<script type="text/javascript">
//平台、设备和操作系统
var system ={
win : false,
mac : false,
xll : false
};
//检测平台
var p = navigator.platform;
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
if(system.win||system.mac||system.xll){
}else{
window.location.href="手机网址";
}
</script>

这个代码放在手机网站模板里面

<script type="text/javascript">
//平台、设备和操作系统
var system ={
win : false,
mac : false,
xll : false
};
//检测平台
var p = navigator.platform;
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
if(system.win||system.mac||system.xll){
window.location.href="PC网址";
}else{
}
</script> 

前言

网站添加鼠标点击弹出指定汉字特效,就是鼠标点击站点任何位置,都会随机弹出我们指定的一组汉字中的一个。比如指定“文明,自由,民主,公正,和谐”等,点击鼠标时就会随机显示这一组的某个词

<script type="text/javascript" charset="utf-8">
var a_idx = 0;
jQuery(document).ready(function($) {
    $(window).click(function(e) {
        var a = new Array("富强", "民主", "文明", "和谐", "自由", "平等", "公正" ,"法治", "爱国", "敬业", "诚信", "友善");
        var $i = $("<span/>").text(a[a_idx]);
        a_idx = (a_idx + 1) % a.length;
        var x = e.pageX,
        y = e.pageY;
        $i.css({
            "z-index": 999999999999999999999999999999999999999999999999999999999999999999999,
            "top": y - 20,
            "left": x,
            "position": "absolute",
            "font-weight": "bold",
            "color": "#ff6651"
        });
        $("body").append($i);
        $i.animate({
            "top": y - 180,
            "opacity": 0
        },
        1500,
        function() {
            $i.remove();
        });
    });
});
</script>

前言

利用PHP把所有的CSS JS 处理压缩成一个文件输出

PHP处理CSS

<?php  
    header('Content-type: text/css');  
    ob_start("compress");  
    function compress($buffer) {  
        $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);  
        $buffer = str_replace(array(" 
        ", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);  
        return $buffer;  
    }  
    include('第一个CSS文件');   //例如当前PHP文件下的 ./main.js
    include('第二个CSS文件');   //复制调用更多JS文件
    ob_end_flush();  //输出压缩后的内容
?>

CSS调用

 <link rel="stylesheet" type="text/css" href="处理CSS的PHP文件地址"/>

PHP处理JS

<?php
    error_reporting(E_ALL & ~E_NOTICE);
    if(extension_loaded('zlib')){
        ob_start('ob_gzhandler');
    }
    header ("content-type:application/x-javascript; charset: UTF-8");
    header ("cache-control: must-revalidate");
    $offset = 60 * 60 * 24; //js文件的距离现在的过期时间,这里设置为一天
    $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
    header ($expire);
    ob_start("compress");
    function compress($buffer) {
        $buffer = preg_replace('/\/\/.*/','', $buffer);
        $buffer = str_replace(array("
        ", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);
        return $buffer;
    }
    include('js文件一'); //例如当前PHP文件下的main.js
    include('js文件二'); //复制调用更多JS文件
    if(extension_loaded('zlib')){
        ob_end_flush(); //输出压缩后的内容
    }
?>

JS调用

<script src="处理JS的PHP文件地址" type="text/javascript" charset="utf-8"></script>