栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

原生JS实现随机点名项目的实例代码

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

原生JS实现随机点名项目的实例代码

核心思想

•随机产生规定范围内的整数,然后再产生相同范围内的整数,两者相同时,则暂停。

所用知识

•Math.random() * num: 产生从0到num的随机数
•Math.floor(): 向下取整
•简单的DOM操作等

技术扩展

•扩展人数
•添加停止键等

效果

代码如下

•html:

 
  

    •css:

     
      * {
       margin: 0;
       padding: 0;
      }
      ul {
       list-style: none;
      }
      body {
       width: 100%;
       height: 100%;
       background: url("images/bg.jpg") no-repeat;
       background-size: cover;
      }
      button {
       border: none;
       background-color: transparent;
       color: #fff;
       font-size: 20px;
      }
      .container {
       width: 1200px;
       height: 700px;
       margin: 10px auto;
      }
      .container .demo, .container .buttonList {
       width: inherit;
       height: 25%;
      }
      .container .students {
       width: inherit;
       height: 50%;
      }
      .container .students li {
       margin-right: 50px;
       margin-bottom: 30px;
       text-align: center;
       border-radius: 10px;
       font-size: 20px;
       font-weight: bold;
      }
      .container .students li:nth-child(5n) {
       margin-right: 0;
      }
      .container .buttonList li button {
       float: left;
       width: 200px;
       height: 60px;
       background-color: #4caf5085;
       margin-right: 150px;
       text-align: center;
       line-height: 60px;
       border-radius: 10px;
       margin-top: 50px;
       font-weight: bold;
      }
      .container .buttonList li button:hover {
       background-color: #4caf50;
      }
      .container .buttonList li:nth-child(1) {
       margin-left: 150px;
      }
      .container .demo li {
       width: 200px;
       height: 150px;
       background-color: #4caf5085;
       float: left;
       margin-right: 150px;
       border-radius: 50%;
       margin-top: 10px;
       line-height: 150px;
       font-weight: bold;
       color: #fff;
       font-size: 60px;
       text-align: center;
      }
      .container .demo li:first-child {
       margin-left: 150px;
      }
     

    •javascript: