亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

獲取隨機顏色

original 2019-02-17 07:46:49 219
abstrait:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>獲取隨機顏色</title><!-- 引入線上jquery文件 --><script src="https://code.jqu

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>獲取隨機顏色</title>

<!-- 引入線上jquery文件 -->

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

<style type='text/css'>

a{

width:150px;

height:150px;

line-height:150px;

display: inline-block;

font-size:12px;

margin-left:10px;

border-radius:50%;

text-align:center;

text-decoration:none;

}

a:hover{

cursor:pointer;

}

button{

width:80px;

height:30px;

line-height:30px;

margin-left:10px;

margin-top:10px;

border:none;

}

p{

width:150px;

text-align:center;

}

</style>

<script type='text/javascript'>

// 隨機數(shù) 函數(shù)

function Rand(min,max){

return Math.floor(Math.random() * (max - min + 1) );

}

// 隨機背景色 函數(shù)

function randRGB(){

return 'rgb(' + Rand(0,255) + ',' + Rand(0,255) + ',' + Rand(0,255) + ')';

}


$(document).ready(function(){

var rand_rgb = '';

// 遍歷a標簽

$('a').each(function(){

// 調(diào)用隨機背景色并賦值給rand_rgb

rand_rgb = randRGB();

// 設置背景 并 顯示背景 值

$(this).css('backgroundColor',rand_rgb).text(rand_rgb);

// 添加hover效果

$(this).hover(

function(){

$(this).stop().animate({'fontSize':'18px','borderRadius':'30px','boxshadow':'0px 0px 30px' + rand_rgb},500);

},function(){

$(this).stop().animate({'fontSize':'12px','borderRadius':'50%','boxshadow':'none'},500);

}

);

// 添加點擊效果

$(this).click(function(){

// 調(diào)用隨機背景色并賦值給rand_rgb

rand_rgb = randRGB();

// 設置a標簽背景 并 顯示背景 值

$(this).css('backgroundColor',rand_rgb).text(rand_rgb);

});

});


//遍歷button標簽

$('button').each(function(val){

// 添加點擊效果

$(this).click(function(){

// 調(diào)用隨機背景色并賦值給rand_rgb

rand_rgb = randRGB();

// 設置a標簽背景 并 顯示背景 值

$(this).parents('div').children('a').css('backgroundColor',rand_rgb).text(rand_rgb);

});

});

});


</script>

</head>

<body>


<div><a>1</a><p><button>隨機顏色</button></p></div>

<div><a>2</a><p><button>隨機顏色</button></p></div>

<div><a>3</a><p><button>隨機顏色</button></p></div>

<div><a>4</a><p><button>隨機顏色</button></p></div>

<div><a>5</a><p><button>隨機顏色</button></p></div>


</body>

</html>


Professeur correcteur:西門大官人Temps de correction:2019-02-17 10:13:26
Résumé du professeur:作業(yè)寫的很好,綜合運用了js和jquery動畫。注釋也很詳細

Notes de version

Entrées populaires