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 " );
?>