首页 技术 正文
技术 2022年11月14日
0 收藏 609 点赞 3,823 浏览 1680 个字
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jquery案例之抽奖</title>
<script type="text/javascript" src="../js/jquery-3.3.1.min.js"></script>
</head>
<body>

<!-- 小像框 -->
<div style="border-style:dotted;width:160px;height:100px">
<img id="img1ID" src="../img/man00.jpg" style="width:160px;height:100px"/>
</div>

<!-- 大像框 -->
<div
style="border-style:double;width:800px;height:500px;position:absolute;left:500px;top:10px">
<img id="img2ID" src="../img/man00.jpg" width="800px" height="500px"/>
</div>

<!-- 开始按钮 -->
<input
id="startID"
type="button"
value="点击开始"
style="width:150px;height:150px;font-size:22px"
onclick="imgStart()">

<!-- 停止按钮 -->
<input
id="stopID"
type="button"
value="点击停止"
style="width:150px;height:150px;font-size:22px"
onclick="imgStop()">

<script language='javascript' type='text/javascript'>
//准备一个一维数组,装用户的像片路径
var imgs = [
"../img/man00.jpg",
"../img/man01.jpg",
"../img/man02.jpg",
"../img/man03.jpg",
"../img/man04.jpg",
"../img/man05.jpg",
"../img/man06.jpg"
];

/*
* 分析:
* 1、给开始按钮绑定单击事件
* 1.1、定义循环定时器
* 1.2、切换小相框src属性
* *定义一个数组,存放图片存放路径
* *生成随机数,数组索引
*
* 2、给结束按钮绑定单击事件
* 2.1、清空定时器
* 2.2、给大相框设置src属性
*
* */
$(function () {
var index;
var interval;
$("#startID").prop("disabled",false);
$("#stopID").prop("disabled",true);
// 1、给开始按钮绑定单击事件
$("#startID").click(function () {
// 1.1、定义循环定时器,20毫米循环一次
interval = setInterval(function () {
//1.2、生成随机角标0~6
index= Math.floor(Math.random()*7);
//1.3、设置小相框src属性
$("#img1ID").prop("src",imgs[index]);
},20);
$("#startID").prop("disabled",true);
$("#stopID").prop("disabled",false);
});

// 2、给结束按钮绑定单击事件
$("#stopID").click(function () {
clearInterval(interval);
$("#img2ID").prop("src",imgs[index]).hide();
$("#img2ID").show(1000);
$("#startID").prop("disabled",false);
$("#stopID").prop("disabled",true);
});
});

</script>
</body>
</html>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,494
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,908
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,133
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297