Implementing a random roll caller based on JavaScript

Implementing a random roll caller based on JavaScript

This article shares the specific code of JavaScript to implement random roll caller for your reference. The specific content is as follows

HTML code:

<body>
 <h1>Roll Call</h1>
 <div id="did">
  <input id="rollcall-id" type="button" value="Random roll call"><br>
  <input id="action-id" type="submit" onclick="doClick()" value="Start">
 </div>
</body>

CSS code:

<style>
 * {
  margin: 0px;
  padding: 0px;
 }

 body {
  background-color: rgb(255, 249, 249);
 }

 h1 {
  text-align: center;
  padding-top: 100px;
  color: rgba(250, 54, 129, 0.562);
 }

 #did {
  position: relative;
  width: 200px;
  margin: 60px auto;
 }

 #did input:first-child {
  width: 200px;
  height: 60px;
  background-color: rgba(250, 54, 129, 0.562);
  /* No border or set the border to transparent*/
  border: none;
  border-radius: 20px;
  font-size: 25px;
  color: #fff;
  box-shadow: 0px 0px 3px 3px rgba(250, 54, 129, 0.158);
  /* Border disappears when clicked*/
  outline: 0;
 }

 #did input:nth-last-child(1) {
  width: 100px;
  height: 40px;
  margin: 40px 50px;
  background-color: rgba(250, 54, 129, 0.562);
  border: 1px solid transparent;
  background-color: rgba(255, 68, 177, 0.432);
  border-radius: 15px;
  box-shadow: 0px 0px 2px 2px rgba(250, 54, 129, 0.158);
  font-size: 17px;
  color: #333;
  outline: 0;
  transition: color 0.2s ease-out;
  transition: box-shadow 0.2s ease-out;
 }

 #did input:nth-last-child(1):hover {
  color: #fff;
  cursor: pointer;
  box-shadow: 0px 0px 4px 4px rgba(250, 54, 129, 0.158);
 }
</style>

JavaScript code:

<script>
 var rollcall = document.getElementById("rollcall-id");
 var action = document.getElementById("action-id");
 var h1 = document.getElementsByTagName("h1");

 //Cannot use name, using name will only get one character var allName = ["Zhang Liufei", "Gao Yingying", "Zhao Wenyan", "Li Ying", "Deng Chenxi", "Mo Ruolin", "Qin Cheng",
  "Wu Xiaoyu", "Zhao Xi", "Ma Suying", "Lü Qinya", "Luo Hongzhe", "Xia Suyun", "Xie Yanzhi",
  "Cao Mengmeng", "Li Yunshu", "Zhou Fengqiao", "Sun Hao", "Jiang Yanjing", "Yang Zhenkai", "Lin Shuyan",
  "Qian Miaomiao", "Guo Jing", "Du Beibei", "Tong Minran", "Zhong Xiaoling", "Han Yunyun", "Bai Ranzhi"];

 //Generate a random name function stringRandom() {
  return parseInt(Math.random() * allName.length);
 }

 var time = null;
 var luckName;
 //Start function doStart() {
  if (time == null) {
   time = setInterval(function () {
    //Get the value of the random name luckName = allName[stringRandom()];
    rollcall.setAttribute("value", luckName);
   }, 100);
  }
 }

 //Stop function doStop() {
  if (time != null) {
   clearInterval(time);
   time = null;
  }
 }

 //Click event function doClick() {
  if (action.value == "start") {
   //Change style action.style.backgroundColor = "#cecece";
   action.style.boxShadow = "0px 0px 2px 2px rgba(100, 100, 100, 0.4)";
   action.value = "Stop";
   h1[0].innerHTML = "Roll roll";

   //Start random roll call doStart();
  } else if (action.value == "Stop") {
   action.style.backgroundColor = "rgba(255, 68, 177, 0.432)";
   action.style.boxShadow = "0px 0px 2px 2px rgba(250, 54, 129, 0.158)";
   action.value = "Start";
   h1[0].innerHTML = "Congratulations" + luckName + "The classmate got a chance to speak";

   //Stop doStop();
  }
 }
</script>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • js implements a simple random color example code for the roll caller
  • js implements a simple random roll caller
  • js implements a simplified version of the random roll caller
  • JS implements random roll caller
  • JavaScript implementation of random roll caller
  • JavaScript implements a simple random roll caller
  • Detailed explanation of the example of random roll caller implemented in JavaScript
  • A random roll call function implemented by javascript
  • A random roll call program using javascript
  • js implements random roll call system (example explanation)

<<:  Key features of InnoDB - insert cache, write twice, adaptive hash index details

>>:  How to install and configure the Apache Web server

Recommend

Media query combined with rem layout in CSS3 to adapt to mobile screens

CSS3 syntax: (1rem = 100px for a 750px design) @m...

js realizes 3D sound effects through audioContext

This article shares the specific code of js to ac...

VUE+Canvas implements the game of God of Wealth receiving ingots

Welcome to the previous canvas game series: 《VUE ...

Manually install mysql5.7.10 on Ubuntu

This tutorial shares the process of manually inst...

Vue implementation example using Google Recaptcha verification

In our recent project, we need to use Google robo...

How to determine if the Linux system is installed on VMware

How to determine whether the current Linux system...

Several methods of implementing two fixed columns and one adaptive column in CSS

This article introduces several methods of implem...

Why is it not recommended to use index as key in react?

1. Compare the old virtual DOM with the new virtu...

Three.js sample code for implementing dewdrop animation effect

Preface Hello everyone, this is the CSS wizard - ...

Basic steps to use Mysql SSH tunnel connection

Preface For security reasons, the root user of My...

Summary of the use of vue Watch and Computed

Table of contents 01. Listener watch (1) Function...

Front-end JavaScript thoroughly understands function currying

Table of contents 1. What is currying 2. Uses of ...

Summary of some common techniques in front-end development

1. How to display the date on the right in the art...

How to Clear Disk Space on CentOS 6 or CentOS 7

Following are the quick commands to clear disk sp...