Dedecms: Summary of random color and font size of tags cloud tags

Source: Internet
Author: User

Modification method:

1. Add the following functions to/include/common. func. php.

The code is as follows:

The code is as follows: Copy code
Function getTagStyle ()
{
$ MinFontSize = 8; // minimum font size, which can be changed as needed
$ MaxFontSize = 18; // maximum font size, which can be changed as needed
Return 'font-size :'. ($ minFontSize + lcg_value () * (abs ($ maxFontSize-$ minFontSize ))). 'px; color :#'. dechbx (rand (0,255 )). dechbx (rand (0,196 )). dechex (rand (0,255 ));

Use the following code to call tags in the template.

The code is as follows:

The code is as follows: Copy code

{Dede: tag row = '45' getall = '1' sort = 'Hot '}
<A href = '[field: link/]' title = "[field: tag/] ([field: total/])" style = "[field: total runphp = yes] @ me = getTagStyle (); [/field: total] "> [field: tag/] </a>
{/Dede: tag}


If you don't want to modify dedecms, we can use js for instances.

The code is as follows: Copy code


<Script src = "/ajax/libs/jquery/1.4.2/jquery. min. js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
Var tags_a =$ ("# tags ");
Tags_a.each (function (){
Var x = 9;
Var y = 0;
Var rand = parseInt (Math. random () * (x-y + 1) + y );
$ (This). addClass ("tags" + rand );
});
})
</Script>

The css code is as follows:
<Style>
Body, a {font-size: 13px ;}
A {color: #333333; text-decoration: none ;}
. Taglist {width: 250px; overflow: hidden; border: # dddddddd solid 1px ;}
. Taglist. tit {width: 100%; height: 24px; line-height: 24px; background-color: #565662 ;}
. Taglist. tit a {padding-left: 8px; color: # ffffff ;}
# Tags a {height: 26px; line-height: 26px; padding-right: 6px ;}
# Tags. tags0 {}
# Tags. tags1 {color: # C00; font-size: 24px ;}
# Tags. tags2 {color: #030; font-size: 16px ;}
# Tags. tags3 {color: # 00F ;}
# Tags. tags4 {font-size: 16px ;}
# Tags. tags5 {color: # C00; font-size: 20px ;}
# Tags. tags6 {color: # F06 font-size: 20px ;}
# Tags. tags7 {color: #030; font-weight: bold; font-size: 18px ;}
# Tags. tags8 {color: # F06; font-weight: bold ;}
# Tags. tags9 {color: # C00; font-weight: bold; font-size: 16px ;}
# Tags a: hover {color: # F00; text-decoration: underline ;}
. W95 {width: 95%; margin: 0 auto; padding-top: 6px; padding-bottom: 6px ;}
. Taglist. w95 {}
</Style>

Html structure:
<Div class = "taglist">
<Div class = "tit"> <a href = "#"> TAG </a> </div>
<Div class = "w95" id = "tags">
You can set your A title here.
</Div>

There is also a simpler

The code is as follows: Copy code

<Script language = "javascript" type = "text/javascript">
Function randomKeywords (){
Var alinks = document. getElementById ("keywords"). getElementsByTagName ("");
Var aColors = new Array ("#990033", "#006666", "# 9966CC", "# FFCC66", "# 6633CC", "# 9999CC ", "#999966", "#996666", "# 9933CC", "# FF99CC ");
Var aSize = new Array ("11px", "12px", "13px", "14px", "15px", "16px", "17px ");
For (var I = 0; I <alinks. length; I ++ ){
Alinks [I]. style. color = aColors [Math. round (aColors. length * Math. random ()];
Alinks [I]. style. fontSize = aSize [Math. round (aSize. length * Math. random ()];
}
}
RandomKeywords ();
</Script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.