Write a tab in PHP by clicking on the font size and color display effect

Source: Internet
Author: User

Set the size and color of the label font by the click-Through tab

This procedure does not consider the program performance and function encapsulation ... Just want to express this algorithm

The specific code is as follows:



? PHP
function Showtag ( $cur = the , $tag = " the Beauty and the Beast " ){
$maxSize = - ; $minSize = - ; // maxsize for label font maximum size, minsize for label minimum size by percent
         $max = - ; $min = 8 ; // Max clicks the maximum number of tabs min for the minimum number of clicks cur The current number of clicks for the current tab
         $tagColor = $tagSize = $minSize ; # tagcolor for label final color, tagsize for label final font size
         $tagSize = @( float )( $cur - $min ) / ( $max - $min ) * ( $maxSize - $minSize );

$colors = Array ( " 0.2 " => " #333333 " , " 0.4 " => " #0033CC " , " 0.6 " => " #660099 " , " 0.8 " => " #00FFFF " , " 1 " => " #FF0000 " );
// color is an array of colors, stored in hundred percent, for example, between 0-0.2 Color1
         $colorkeys = Array_keys ( $colors );

$select = ( float )( $cur - $min ) / ( $max - $min );
$len = Count ( $colorkeys );
$i = 0 ; $j = $len - 1 ;
while ( $i < $j ){ // Two-point search
             $index = ( $i + $j ) / 2 ;
if ( $select >= ( float ) $colorkeys [ $index ]  &&   $select < ( float ) $colorkeys [ $index + 1 ])  Break ;
ElseIf ( $select < ( float ) $colorkeys [ $index ])  $j -- ;
ElseIf ( $select > ( float ) $colorkeys [ $index ])  $i ++ ;
ElseIf ( $select == ( float ) $colorkeys [ $index + 1 ])  Break ;
Else   Break ;
}
$tagColor = $colors [ $colorkeys {( $i + $j ) / 2 }];
Echo   " <span style= ' font-size:${tagsize}%;color: $tagColor ' > $tag </span> " ;
}
Showtag ( the ); Showtag ( A , " shareholders " ); Showtag ( - M , " my love. " ); Showtag ( - , " MM " );
?>


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.