获取随机颜色

Original 2018-11-14 10:39:33 193
abstract:<a href="">1</a> <a href="">2</a> <a href="">3</a> <a href="">4</a>a{display: block;
<a href="">1</a>
	<a href="">2</a>
	<a href="">3</a>
	<a href="">4</a>
a{display: block;width: 100px;height: 100px;line-height:100px;margin:100px;text-decoration: none;text-align: center;float: left;border-radius: 50px;}
function changeColor(tag){
			var len = document.getElementsByTagName(tag).length;
			for(var i=0;i<len;i++){
				document.getElementsByTagName(tag)[i].style.backgroundColor = 'rgb('+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+')';
			}
			//document.write('rgb('+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+')');
		}
		$(document).ready(function(){
			changeColor('a');
			$('a').mouseover(function(){
				$color = $(this).css('backgroundColor');//获取当前颜色,给光晕填充
				$(this).css('box-shadow','0px 0px 20px '+$color);
				$(this).css('border-radius','20px');
			});

			$('a').mouseout(function(){
				$(this).css('box-shadow','none');
				$(this).css('border-radius','50px');				
			});
		});

QQ图片20181114103819.png

Correcting teacher:灭绝师太Correction time:2018-11-14 10:44:02
Teacher's summary:还有很多不同写法,可以自己尝试,把所学习的知识学以致用很重要!

Release Notes

Popular Entries