当前位置: 代码迷 >> Web前端 >> 自个儿写的TagBOX-随机变换的字体颜色和大小
  详细解决方案

自个儿写的TagBOX-随机变换的字体颜色和大小

热度:171   发布时间:2012-10-07 17:28:51.0
自己写的TagBOX---随机变换的字体颜色和大小
<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
		
		<script type="text/javascript">
			$(function(){
				var config = {
					renderTo : "foo" ,
					tags : [
						"JQuery","Prototype","ExtJS","Dojo","Yahoo-YUI","MooTools",
						"Script.Aculo.Us","MochiKit","Rialto","Spry Framework","QooXdoo","Zepo"
					]
				} ;
				TagBOX.load(config) ;
			}) ;
			var TagBOX = function(){
				function load(config){
					var renderTo = $(document.getElementById(config.renderTo)) ;
					var tags = config.tags ;
					_render(renderTo,tags) ;
				} ;
				function _render(renderTo,tags){
					var tagBox = $("<div></div>")
								.addClass("tag-box")
								.appendTo(renderTo) ;
					var close = $("<div></div>")
								.addClass("close")
								.appendTo(tagBox) ;
					var _a = $("<a href='#'></a>")
							.html("打开/关闭")
							.appendTo(close)
							.click(function(){
								var jq = $(this).parent().next().slideToggle() ;
							}) ;
					var _ul = $("<ul></ul>").appendTo(tagBox) ;
					for(var i=0;i<tags.length;i++){
						var tag = tags[i] ;
						var _css = _getStyle() ;
						
						var _li = $("<li></li>").appendTo(_ul) ;
						var _a_ = $("<a href=''></a>")
								.html(tag)
								.css(
									{
										color : _css.color ,
										fontSize : _css.size
									}
								)
								.appendTo(_li) ;
					}
				} ;
				function _getStyle(){
					var sizes = ["11","12","13","14","15","16","18"] ;
					var colors = ["#000","#ff0033","#336699","brown","green","puple","#ffcc00"] ;
					var _style = new Object() ;
					_style.color = colors[parseInt(Math.random() * colors.length)] ;
					_style.size = parseInt(sizes[parseInt(Math.random() * sizes.length)]) ;
					return _style ;
				} ;
				return {
					load : load
				} ;
			}() ;
		</script>

?

  相关解决方案