分类 代码 下的文章

css3 + jquery 实现颜色渐变滚动条

js 代码

$(window).scroll(function(){
 var s=$(window).scrollTop();//滚动条和顶部的距离,默认单位:px. 
//所以当$(window).scrollTop()的值等于0时,就表示滚动条在最顶部。
 var a=$(document).height();//页面文档的总高度
 var b=$(window).height();//窗口能显示的最大高度
//页面文档高度-窗口的最大高度=s的最大值。即滚动条需要滚动的最大距离
 var result=parseInt(s/(a-b)*100);
//所以s/(a-b)就是滚动条相对于窗口的百分比。 
 $("#bar").css("width",result+"%");
 if(result>=0&&result<=19)
 $("#bar").css("background","#cccccc");
 if(result>=20&&result<=39)
 $("#bar").css("background","#50bcb6");
 if(result>=40&&result<=59)
 $("#bar").css("background","#85c440");
 if(result>=60&&result<=79)
 $("#bar").css("background","#f2b63c");
 if(result>=80&&result<=99)
 $("#bar").css("background","#FF0000");
 if(result==100)
 $("#bar").css("background","#5aaadb");
});

阅读全文

顶部滚动条(预览页面剩余长度)

html 代码

<div id="load"></div>
css 代码
#load {
    background-color: #2299dd;
    height: 2px;
    width: 0px;
    position: fixed;
    left: 0px;
    top: 0px;
    z-index: 9999;
}
js 代码
$(function() {
    function scroll_fn() {
        document_height = $(document).height();
        scroll_so_far = $(window).scrollTop();
        window_height = $(window).height();
        max_scroll = document_height - window_height;
        scroll_percentage = scroll_so_far / (max_scroll / 100);
        $('#load').width(scroll_percentage + '%')
    }
    $(window).scroll(function() {
        scroll_fn()
    });
    $(window).resize(function() {
        scroll_fn()
    })
});

阅读全文

centos 开启端口服务

查看所有端口情况

netstat -ano

开启 465 端口

/sbin/iptables -I INPUT -p tcp --dport 465 -j ACCEPT   写入修改
/etc/init.d/iptables save                              保存修改
service iptables restart                               重启防火墙,修改生效

查看 465 端口详情

netstat -an | grep 465

PHP 随机输出一句话

function.php 文件中添加代码

function random_str() { 
$poems="Hello World
已知花意,未见其花,已见其花,未闻花名
如果能不长大就好了啊,可是时光在身后挡住退路
或许前路永夜,即便如此我也要前进,因为星光即使微弱也会为我照亮前路
你驻足于春色中,于那独一无二的春色之中
生活是不公平的,要去适应它"; 
$poems=explode("\n",$poems); 
return $poems[rand(0,count($poems)-1)]; 
} 
function says(){ 
    $says=random_str(); 
    echo $says; 
}

阅读全文

Typecho 设置评论者链接从新窗口中打开

修改 Comments.php 文件
文件所在位置 /var/Widget/Abstract/Comments.php
修改代码(约第 376 行)

//echo '<a href="' , $this->url , '"' , ($noFollow ? ' rel="external nofollow"' : NULL) , '>' , $this->author , '</a>';//原代码
echo '<a href="' , $this->url , '"' , ($noFollow ? ' rel="external nofollow"' : NULL) ,  ' target="_blank" ' ,'>' , $this->author , '</a>';//添加_blank属性

Typecho 计算文章字数

将以下代码插入到主题中的 functions.php 文件中

function  art_count ($cid){
    $db=Typecho_Db::get ();
    $rs=$db->fetchRow ($db->select ('table.contents.text')->from ('table.contents')->where ('table.contents.cid=?',$cid)->order ('table.contents.cid',Typecho_Db::SORT_ASC)->limit (1));
    $text = preg_replace("/[^\x{4e00}-\x{9fa5}]/u", "", $rs['text']);
    echo mb_strlen($text,'UTF-8');
}

阅读全文