利用按钮控制圆变色变形案例

原创 2019-02-03 22:45:23 218
摘要:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">&

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<script type="text/javascript" src="jquery-3.3.1.min.js">

</script>

<style>

a{

width: 200px;

height: 200px;

float: left;

border-radius: 50%;

border:1px solid black;

margin:40px;

text-align: center;

line-height: 200px;

display: block;

color: #fff;

text-decoration: none;

}

#btn{

margin: 0 auto;

}

</style>

<title>导航条案例</title>

</head>

<body>

<a href="#">1</a>

<a href="#">2</a>

<a href="#">3</a>

<a href="#">4</a>

<button id="btn1">点击变色变形</button><button id="btn2">点击变色变形</button>

<script>

function aa(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).ready(function(){

aa('a')

$('#btn1').click(function(){

$bg=$('a').css('backgroundColor');

$('a').css('box-shadow','0px 0px 20px '+$bg);

$('a').css('border-radius','20px');

})

$('#btn2').click(function(){

$('a').css('box-shadow','none');

$('a').css('border-radius','50%');

})

})

</script>

</body>

</html>


批改老师:韦小宝批改时间:2019-02-11 09:11:18
老师总结:写的很不错 主要是练习了很多函数 这些函数在以后的开发中可能都会起到作用

发布手记

热门词条