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

獲取隨機(jī)顏色動(dòng)畫總結(jié)

原創(chuàng) 2018-10-30 12:45:38 329
摘要:模仿案例<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>獲取隨機(jī)顏色</title> <script type="text/javascript" src="j

模仿案例

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>獲取隨機(jī)顏色</title>
<script type="text/javascript" src="jquery-3.3.1.min.js">
</script>
<style>
a{  float: left;
display: inline-block;
margin:50px;
width: 100px;
height: 100px;
line-height: 100px;
text-align: center;
text-decoration: none;
color: pink;
border-radius: 20px;
}
</style>
<script type="text/javascript">

function getcoler(tag){
var length=document.getElementsByTagName(tag).length//獲取a標(biāo)簽的個(gè)數(shù)
for (var i = 0; i<length; i++) {
document.getElementsByTagName(tag)[i].style.backgroundColor='rgb('+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+')'
//為每個(gè)a標(biāo)簽獲取隨機(jī)顏色值,顏色值用rgb('')表示,具體數(shù)值值用隨機(jī)函數(shù)Math.random()和取整函數(shù)獲得Math.floor()
}
}
$(document).ready(function(){
getcoler('a')
$('a').mouseover(function(){
a_rgb=$(this).css('backgroundColor')//獲取a標(biāo)簽的背景顏色
$(this).css('box-shadow','0px 0px 20px '+a_rgb)
//為當(dāng)前a標(biāo)簽的加上同顏色的陰影 $(this)括號(hào)里不用加''
//注意'0px 0px 20px '每個(gè)值后都要有空格,包括20px后面
$(this).css('border-radius','50px')
}),

$('a').mouseleave(function(){
$(this).css('box-shadow','none')
//為當(dāng)前a標(biāo)簽的去掉的陰影
$(this).css('border-radius','20px')
})

})
</script>
</head>
<body>
<a href="#">1</a>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>
</body>
</html>


發(fā)佈手記

熱門詞條