酷炫的随机点名 可手动控制概率的html

时间: 2023-11-06 10:08:47 浏览: 33
代码如下: ```html <!DOCTYPE html> <html> <head> <title>随机点名</title> <style type="text/css"> body { background-color: #f1f1f1; font-family: Arial, sans-serif; font-size: 16px; } h1 { text-align: center; margin-top: 50px; } .btn-container { display: flex; justify-content: center; margin-top: 50px; } .btn { background-color: #4CAF50; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; margin-right: 10px; } .btn:hover { background-color: #3E8E41; } .input-container { display: flex; justify-content: center; margin-top: 50px; } .input { padding: 10px; border-radius: 5px; border: none; margin-right: 10px; width: 100px; text-align: center; } .result-container { display: flex; flex-wrap: wrap; justify-content: center; margin-top: 50px; } .result { background-color: #ddd; padding: 10px; border-radius: 5px; margin: 10px; font-weight: bold; text-align: center; width: 100px; height: 100px; display: flex; flex-direction: column; justify-content: center; align-items: center; cursor: pointer; transition: all 0.2s ease-in-out; } .result:hover { background-color: #bbb; } .result.selected { background-color: #4CAF50; color: white; } </style> </head> <body> <h1>随机点名</h1> <div class="btn-container"> <button class="btn" onclick="start()">开始</button> <button class="btn" onclick="stop()">停止</button> <button class="btn" onclick="reset()">重置</button> </div> <div class="input-container"> <label>概率(%):</label> <input type="number" class="input" min="0" max="100" value="50" oninput="setProbability()"> </div> <div class="result-container"> <div class="result"></div> </div> <script type="text/javascript"> var intervalId; var probability = 50; var selected = null; function start() { if (!intervalId) { intervalId = setInterval(selectRandom, 100); } } function stop() { if (intervalId) { clearInterval(intervalId); intervalId = null; selected.classList.add('selected'); } } function reset() { if (intervalId) { clearInterval(intervalId); intervalId = null; } selected = null; document.querySelectorAll('.result').forEach(function(result) { result.classList.remove('selected'); }); } function setProbability() { probability = parseInt(document.querySelector('.input').value); } function selectRandom() { document.querySelectorAll('.result').forEach(function(result) { result.classList.remove('selected'); }); var random = Math.floor(Math.random() * 100); if (random < probability) { selected = document.querySelectorAll('.result')[Math.floor(Math.random() * document.querySelectorAll('.result').length)]; } } document.querySelectorAll('.result').forEach(function(result) { result.addEventListener('click', function() { if (selected === result) { result.classList.remove('selected'); selected = null; } else { document.querySelectorAll('.result').forEach(function(result) { result.classList.remove('selected'); }); result.classList.add('selected'); selected = result; } }); }); </script> <script type="text/javascript"> var names = ['张三', '李四', '王五', '赵六', '孙七', '周八', '吴九', '郑十']; for (var i = 0; i < 8; i++) { document.querySelectorAll('.result')[i].innerHTML = names[i]; } </script> </body> </html> ``` 效果如下: ![随机点名](https://i.loli.net/2021/08/01/rjKlS1CvL7bJxkW.png)

相关推荐

最新推荐

recommend-type

基于html和CSS3制作酷炫的导航栏

 4 li控制边框样式  5 使用html + css3 渐变画图 制作背景图片  6 更改颜色透明度  7 DIV制作边框阴影 先看效果图:   CSS Code复制内容到剪贴板 &lt;!doctype html&gt;  html lang="en"&gt;  &lt;head&gt;...
recommend-type

25个实用酷炫的Android开源UI框架

本文为大家分享了25个实用酷炫的Android开源UI框架,灵活运用这些UI框架可在日常工作中节省不少时间
recommend-type

基于 Vue 实现一个酷炫的 menu插件

本文给大家介绍基于 Vue 实现一个酷炫的 menu插件,此篇教程需要大家具备一定的css和vue基础知识,本文分步骤给大家介绍的非常详细,需要的朋友参考下吧
recommend-type

Android酷炫动画效果之3D星体旋转效果

本文要实现的3D星体旋转效果是从CoverFlow演绎而来,不过CoverFlow只是对图像进行转动,我这里要实现的效果是要对所有的View进行类似旋转木马的转动
recommend-type

数据库实验.py

数据库实验.py
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

SQL怎么实现 数据透视表

SQL可以通过使用聚合函数和GROUP BY子句来实现数据透视表。 例如,假设有一个销售记录表,其中包含产品名称、销售日期、销售数量和销售额等信息。要创建一个按照产品名称、销售日期和销售额进行汇总的数据透视表,可以使用以下SQL语句: ``` SELECT ProductName, SaleDate, SUM(SaleQuantity) AS TotalQuantity, SUM(SaleAmount) AS TotalAmount FROM Sales GROUP BY ProductName, SaleDate; ``` 该语句将Sales表按照ProductName和SaleDat
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。