1. 程式人生 > >派大星博客的美化之路

派大星博客的美化之路

setattr document onf attr onos http parent begin 大小

主題

SimpleMemory

更改背景顏色、標題、子標題

css

#blogTitle h1 a {
    color: #515151;
background: #EEE url(data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAHklEQVQImWNkYGBgYGD4//8/A5wF5SBYyAr+//8PAPOCFO0Q2zq7AAAAAElFTkSuQmCC) repeat;
text-shadow: 5px -5px black, 4px -4px white;
font-weight: bold;
-webkit-text-fill-color: transparent; -webkit-background-clip: text } .vintage2{ color: transparent; -webkit-text-stroke: 1px red; letter-spacing: 0.04em;} .vintage3 { color: transparent; background-color : blue; text-shadow : rgba(255,255,255,0.5) 0 5px 6px, rgba(255,255,255,0.2) 1px 3px 3px;
-webkit-background-clip : text; } #blogTitle h2 { left: auto; font-weight: normal; font-size: 13px; font-size: 0.928571429rem; line-height: 1.846153846; color: #258ce4; float: left; padding-left: 150px; font-family: monospace; animation: change 8s linear 0s infinite; } @keyframes change{
0% { color: #1f58dc; } 10% { color: #9ab2ea; } 20% { color: #ff0; } 30% { color: #666d55; } 40% { color: #1f58dc; } 50% { color: #ad4d0d; } 60% { color: #3360ca; } 70% { color: #108883; } 80% { color: #238434; } 90% { color: #b0e418; } 100% { color: #d09292; }} body { background: #c1d8d2; }

添加下雪效果

<script type="text/javascript">
    /* 控制下雪 */
    function snowFall(snow) {
        /* 可配置屬性 */
        snow = snow || {};
        this.maxFlake = snow.maxFlake || 200;   /* 最多片數 */
        this.flakeSize = snow.flakeSize || 10;  /* 雪花形狀 */
        this.fallSpeed = snow.fallSpeed || 1;   /* 墜落速度 */
    }
    /* 兼容寫法 */
    requestAnimationFrame = window.requestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        window.oRequestAnimationFrame ||
        function(callback) { setTimeout(callback, 1000 / 60); };
 
    cancelAnimationFrame = window.cancelAnimationFrame ||
        window.mozCancelAnimationFrame ||
        window.webkitCancelAnimationFrame ||
        window.msCancelAnimationFrame ||
        window.oCancelAnimationFrame;
    /* 開始下雪 */
    snowFall.prototype.start = function(){
        /* 創建畫布 */
        snowCanvas.apply(this);
        /* 創建雪花形狀 */
        createFlakes.apply(this);
        /* 畫雪 */
        drawSnow.apply(this)
    }
    /* 創建畫布 */
    function snowCanvas() {
        /* 添加Dom結點 */
        var snowcanvas = document.createElement("canvas");
        snowcanvas.id = "snowfall";
        snowcanvas.width = window.innerWidth;
        snowcanvas.height = document.body.clientHeight;
        snowcanvas.setAttribute("style", "position:absolute; top: 0; left: 0; z-index: 1; pointer-events: none;");
        document.getElementsByTagName("body")[0].appendChild(snowcanvas);
        this.canvas = snowcanvas;
        this.ctx = snowcanvas.getContext("2d");
        /* 窗口大小改變的處理 */
        window.onresize = function() {
            snowcanvas.width = window.innerWidth;
            /* snowcanvas.height = window.innerHeight */
        }
    }
    /* 雪運動對象 */
    function flakeMove(canvasWidth, canvasHeight, flakeSize, fallSpeed) {
        this.x = Math.floor(Math.random() * canvasWidth);   /* x坐標 */
        this.y = Math.floor(Math.random() * canvasHeight);  /* y坐標 */
        this.size = Math.random() * flakeSize + 2;          /* 形狀 */
        this.maxSize = flakeSize;                           /* 最大形狀 */
        this.speed = Math.random() * 1 + fallSpeed;         /* 墜落速度 */
        this.fallSpeed = fallSpeed;                         /* 墜落速度 */
        this.velY = this.speed;                             /* Y方向速度 */
        this.velX = 0;                                      /* X方向速度 */
        this.stepSize = Math.random() / 30;                 /* 步長 */
        this.step = 0                                       /* 步數 */
    }
    flakeMove.prototype.update = function() {
        var x = this.x,
            y = this.y;
        /* 左右擺動(余弦) */
        this.velX *= 0.98;
        if (this.velY <= this.speed) {
            this.velY = this.speed
        }
        this.velX += Math.cos(this.step += .05) * this.stepSize;
 
        this.y += this.velY;
        this.x += this.velX;
        /* 飛出邊界的處理 */
        if (this.x >= canvas.width || this.x <= 0 || this.y >= canvas.height || this.y <= 0) {
            this.reset(canvas.width, canvas.height)
        }
    };
    /* 飛出邊界-放置最頂端繼續墜落 */
    flakeMove.prototype.reset = function(width, height) {
        this.x = Math.floor(Math.random() * width);
        this.y = 0;
        this.size = Math.random() * this.maxSize + 2;
        this.speed = Math.random() * 1 + this.fallSpeed;
        this.velY = this.speed;
        this.velX = 0;
    };
    // 渲染雪花-隨機形狀(此處可修改雪花顏色!!!)
    flakeMove.prototype.render = function(ctx) {
        var snowFlake = ctx.createRadialGradient(this.x, this.y, 0, this.x, this.y, this.size);
        snowFlake.addColorStop(0, "rgba(255, 255, 255, 0.9)");  /* 此處是雪花顏色,默認是白色 */
        snowFlake.addColorStop(.5, "rgba(255, 255, 255, 0.5)"); /* 若要改為其他顏色,請自行查 */
        snowFlake.addColorStop(1, "rgba(255, 255, 255, 0)");    /* 找16進制的RGB 顏色代碼。 */
        ctx.save();
        ctx.fillStyle = snowFlake;
        ctx.beginPath();
        ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
        ctx.fill();
        ctx.restore();
    };
    /* 創建雪花-定義形狀 */
    function createFlakes() {
        var maxFlake = this.maxFlake,
            flakes = this.flakes = [],
            canvas = this.canvas;
        for (var i = 0; i < maxFlake; i++) {
            flakes.push(new flakeMove(canvas.width, canvas.height, this.flakeSize, this.fallSpeed))
        }
    }
    /* 畫雪 */
    function drawSnow() {
        var maxFlake = this.maxFlake,
            flakes = this.flakes;
        ctx = this.ctx, canvas = this.canvas, that = this;
        /* 清空雪花 */
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        for (var e = 0; e < maxFlake; e++) {
            flakes[e].update();
            flakes[e].render(ctx);
        }
        /*  一幀一幀的畫 */
        this.loop = requestAnimationFrame(function() {
            drawSnow.apply(that);
        });
    }
    /* 調用及控制方法 */
    var snow = new snowFall({maxFlake:500});
    snow.start();
</script>

添加目錄

--可以直接插在頁腳HTML代碼--

<div id="div_digg1" align="center"><p id="bfq"  ></p></div>
<style>
* {
    margin: 0;
    padding: 0;
    border: 0;
}
#div_digg1 {
    padding: 5px;
    position: fixed;
    _position: absolute;
    z-index: 1000;
    bottom: 10px;
    left:10px;
    _left: 15px;
    border: 0;
}
#back-top {
     position: fixed;
     bottom: 10px;
     right: 80px;
     z-index: 99;
}
#back-top span {
     width: 50px;
     height: 64px;
     display: block;
     background:url(http://images.cnblogs.com/cnblogs_com/seanshao/855033/o_rocket.png) no-repeat center center;
}
#back-top a{outline:none}
</style>
<script type="text/javascript">
$(function() {
    // hide #back-top first
    $("#back-top").hide();
    // fade in #back-top
    $(window).scroll(function() {
        if ($(this).scrollTop() > 500) {
            $(#back-top).fadeIn();
        } else {
            $(#back-top).fadeOut();
        }
    });
    // scroll body to 0px on click
    $(#back-top a).click(function() {
        $(body,html).animate({
            scrollTop: 0
        }, 800);
        return false;
    });
});
</script>
<p id="back-top" style="display:none"><a href="#top"><span></span></a></p>
<div class="fixedIndexs" style="position: fixed;bottom: 40px;display: none"></div>
<script language="javascript" type="text/javascript">
    var fixedIndexs=$(.fixedIndexs);
    var hs = $(#cnblogs_post_body h2);
    function openorclose(a) {
        $("#indexs").slideToggle("fast");
        var text=$(a).text();
        if(text==[-]){
            $(a).text("[+]");
            return;
        }
        $(a).text("[-]");
    }
    function createIndexs(){
        var indexs_container=$(<div style="border:solid 1px #ccc; background:#eee;width:180px;padding:4px 10px;"></div>);
        var indexs_controller=$(<p style="text-align:right;margin:0;"><span style="float:left;">目錄<a onclick="javascript:openorclose(this);" style="cursor: pointer">[-]</a></span><a href="#top" style="text-align: right;color: #444">返回頂部</a></p>);
        var indexs=$(<ol id="indexs" style="margin-left: 14px; padding-left: 14px; line-height: 160%; display: block;"></ol>);
        indexs_container.append(indexs_controller).append(indexs);
        $.each(hs,function(i,h){
            $(h).before(<a name="index_+i+"></a>);
            indexs.append(<li style="list-style:decimal"><a href="#index_+i+" id="active_+i+">+$(h).text()+</a></li>);
        });
        if(hs.length!=0){
            fixedIndexs.append(indexs_container);
            //get home div right offset
            fixedIndexs.css(right,$("#home").offset().left+32+px);
        }
    }
    createIndexs();
    $(window).scroll(function(event){
        //clear all active
        $("#indexs li a").removeClass("active");
        //set active
        $.each(hs,function (i, h) {
            var next_active_top;
            i<(hs.length-1)?next_active_top=hs.eq(i+1).offset().top:hs.last().offset().top;
            if($(h).offset().top<$(window).scrollTop()+30&&$(window).scrollTop()+30<next_active_top){
                $("#active_"+i).addClass("active");
            }
            if(i+1==hs.length&&$(window).scrollTop()+30>hs.last().offset().top){
                $("#active_"+i).addClass("active");
            }
        });
        //auto display
        if($(window).scrollTop()>$(window).height()){
            fixedIndexs.show();
            return;
        }
        fixedIndexs.hide();
    });
    $(window).resize(function (event) {
        fixedIndexs.hide();
        fixedIndexs.css(right,$("#home").offset().left+32+px);
        if($(window).scrollTop()>$(window).height()){
            fixedIndexs.show();
        }
    })
</script>

派大星博客的美化之路