返回jquery的......登陆

jquery的随机颜色

Risco2018-12-21 11:49:55274

老师讲的很清楚 但是理解有点理解不太明白   


<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

<style type="text/css">

*{margin:0px;padding: 0px;list-style: none;margin:0px auto;}

a{float: left;

  display: block;

  width: 80px;

  height: 80px;

  background-color: #ccc;

  margin:20px;

  line-height: 100px;

  text-align: center;

  text-decoration: none;

  border-radius: 50px;




}





</style>

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

</head>

<body>

<script type="text/javascript">

      function bb(adc){   //命名

       var len=document.getElementsByTagName(adc).length  //声明变量获取标签元素 获取命名的标签长度

       for(var i=0;i<len;i++){//for循环初始化变量i=0,循环条件i<len,循环不长  I++

       document.getElementsByTagName(adc)[i].style.backgroundColor='rgb('+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+')'  //获取abc的元素 找到下面的[i]连接css的背景颜色,rgb的颜色值  rag获取值  Math.random获取随机颜色值*256  在256个颜色值选择的 选取后面的小数Math.floor四舍五入的方法    

           

       }

      }

        $(document).ready(function(){

            bb('a')                //调用bb的函数

           $('a').mouseover(function(){  //移动上面的效果

            $bg=$(this).css('backgroundColor')  //声明bg  获取当前的背景色

            $(this).css('box-shadow','0px 0px 20px '+$bg)//给阴影  在获取背景

            $(this).css('border-radius','20px ')   //给边框给20个px的变形

           })

            $('a').mouseleave(function(){   //当鼠标移出

            $(this).css('box-shadow','none')//移除后 去除阴影

            $(this).css('border-radius','50px ') //在给边框50的变形

           })

        })

</script>


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

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

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

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

<a href="">5</a>

<a href="">6</a>

<a href="">5</a>

<a href="">6</a>

</body>

</html>


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送