网站tag标签属性原理与jquery特效分析

特效:

 

代码:

     1:html代码:

    

 1 .tag-cloud .tag {
 2   display: inline-block;
 3   *display: inline;
 4   *zoom: 1;
 5   padding: 1px 4px;
 6   font-size: 12px;
 7   margin: 0 5px 4px 0;
 8   color: #FFF;
 9   white-space: nowrap;
10 }
11 .tag-1 {
12   background-color: #ffaa01;
13 }
14 .tag-1:hover,
15 .tag-1:active {
16   background-color: #cd8800;
17 }
18 .tag-2 {
19   background-color: #bfd671;
20 }
21 .tag-2:hover,
22 .tag-2:active {
23   background-color: #adcb49;
24 }
25 .tag-3 {
26   background-color: #8ed1e0;
27 }
28 .tag-3:hover,
29 .tag-3:active {
30   background-color: #66c1d5;
31 }
32 .tag-4 {
33   background-color: #c098d3;
34 }
35 .tag-4:hover,
36 .tag-4:active {
37   background-color: #aa74c4;
38 }
39 .tag-5 {
40   background-color: #f29c9f;
41 }
42 .tag-5:hover,
43 .tag-5:active {
44   background-color: #ec6f73;
45 }
46 .tag-6 {
47   background-color: #88abda;
48 }
49 .tag-6:hover,
50 .tag-6:active {
51   background-color: #6190ce;
52 }
53 .tag-7 {
54   background-color: #89c997;
55 }
56 .tag-7:hover,
57 .tag-7:active {
58   background-color: #66b978;
59 }
View Code
<div class="box box-side box-news-index news-index-tagCloud">
    
    <div class="boxs-title">
        <h4>最近搜索</h4>
    </div>
        <div class="conleftbox" style="background-color: #FFFFFF;">
            {foreach from=last_search() key=key name=pro_num item=val}
            <a href="/keyword/{$val.filename}.html" target="_blank" class="" style="color: #FFFFFF;">{$val.keyword}</a>&nbsp;
            {/foreach}
        </div>
        <script>
            $(document).ready(function(){
                var a = $(".conleftbox a").length;

                for(var i=0;i<a;i++){
                    if(i%3==0){
                        $(".conleftbox a").eq(i).addClass("tag tag-2");
                    }else if(i%5==0){
                        $(".conleftbox a").eq(i).addClass("tag tag-4");
                    }else if(i%7==0){
                        $(".conleftbox a").eq(i).addClass("tag tag-6");
                    }else if(i%9==0){
                        $(".conleftbox a").eq(i).addClass("tag tag-7");
                    }else if(i%11==0){
                        $(".conleftbox a").eq(i).addClass("tag tag-1");
                    }else if(i%4){
                        $(".conleftbox a").eq(i).addClass("tag tag-3");
                    }else{
                        $(".conleftbox a").eq(i).addClass("tag tag-5");
                    }
                }
            });
        </script>
    
</div>

 

2:php代码:

function hot_search($label_num = 11){
    static $res = NULL;

    if ($res === NULL)
    {
        $data = read_static_cache('hot_search');
        if ($data === false)
        {
            $res = $GLOBALS['db']->getAll("SELECT keyword,filename FROM " . $GLOBALS['ecs']->table('keywords') . " WHERE is_show = '1' and searchengine = 'ecshop' and length(keyword)<=40 ORDER BY RAND() LIMIT 0,99");
            write_static_cache('hot_search', $res);
        }
        else
        {
            $res = $data;
        }
    }
    $tempArr = array();
    $labelArr = array();

    if ( $label_num ){
        $tempArr = @array_rand($res,$label_num);//随机取出二维数组的键

        if(is_array($tempArr)){
            foreach ( $tempArr as $value ){
                $labelArr[] = $res[$value];
            }
        }
    }
    unset($res,$tempArr);
    return $labelArr;
}
function last_search()
{
    return hot_search(33);
}

 

posted @ 2017-02-10 14:51  王传明  阅读(181)  评论(0)    收藏  举报