zoukankan      html  css  js  c++  java
  • 标签随机文字颜色和字体大小的实现方法

    先上效果图:
    在这里插入图片描述
    实现代码:

    <script type="text/javascript">
        $(document).ready(function(){
          var obj=$("#wrap a");//获取a标签中的数据
          function rand(num){
          //parseInt();将字符串转为整数
          //Math.random();生成随机数
          return parseInt(Math.random()*num+1);
          }
       
          function randomcolor(){
            var str=Math.ceil(Math.random()*16777215).toString(16);
            if(str.length<6){
            str="0"+str;
            }
            return str;
          }
       
          for(len=obj.length,i=len;i--;){
            obj[i].style.left=rand(600)+"px";//标签左右间距
            obj[i].style.top=rand(400)+"px";//标签上下间距
            obj[i].className="color"+rand(5);
            obj[i].style.zIndex=rand(5);//设置元素的堆叠顺序
            obj[i].style.fontSize=rand(5)+18+"px";//随机字体大小这里是18-23
            obj[i].style.color="#"+randomcolor();//字体颜色
            obj[i].style.padding=rand(15)+"px";
          }
        });
    </script>
    

    html中直接在div设置id=“wrap”,用<c:forEach>遍历标签。
    在这里插入图片描述

  • 相关阅读:
    第九周学习进度
    用户场景描述
    第九天
    第10天
    求两个有序数组的中值
    计算字符串中最长子字符串的长度
    计算两个数之和
    将string 转int
    判断一个int 型整数 是否为回文数
    php 对象的一些特性
  • 原文地址:https://www.cnblogs.com/does/p/13621484.html
Copyright © 2011-2022 走看看