当前位置:网站首页>原生js系列
原生js系列
2022-07-30 17:52:00 【YingUser】
1、图片的切换
包含了定时器以及修改属性的属性
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>图片切换</title>
</head>
<body>
<img src="./images/1.jpg" alt="" id="flower" width="200" height="200">
<br>
<br>
<button id="preBtn">上一张</button> <button id="nexBtn">下一张</button>
<script type="text/javascript">
let flower = document.getElementById('flower')
let preBtn = document.getElementById('preBtn')
let nexBtn = document.getElementById("nexBtn")
let minIndex = 1, maxIndex = 5; currentIndex = minIndex
// 上一张
nexBtn.onclick = function () {
if (currentIndex === maxIndex) {
currentIndex = minIndex
} else {
currentIndex++
}
console.log(currentIndex);
flower.setAttribute('src', `images/${currentIndex}.jpg`)
}
// 下一张
preBtn.onclick = function () {
if (currentIndex === minIndex) {
currentIndex = maxIndex
} else {
currentIndex--
}
console.log(currentIndex);
flower.setAttribute('src', `images/${currentIndex}.jpg`)
}
// 定时器切换
let timer = setInterval(() => {
currentIndex++
if (currentIndex === maxIndex) {
currentIndex = minIndex
}
flower.setAttribute('src', `images/${currentIndex}.jpg`)
}, 3000)
</script>
</body>
</html>2、图片的显示与隐藏
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>图片的显示和隐藏</title>
</head>
<body>
<button id="btn">隐藏</button>
<br>
<img src="./images/10.jpg" alt="" id="new">
<script type="text/javascript">
// 1、获取事件源
let oBtn=document.getElementById('btn')
let newImg=document.getElementsByTagName('img')[0]
// let isShow=true 这是另外一种方法,用一个变量控制
// 绑定事件
oBtn.onclick=function(){
// 事件驱动程序
if(oBtn.innerHTML==='隐藏'){
newImg.style.display = 'none'
oBtn.innerHTML='显示'
// isShow=false
}else{
newImg.style.display = 'block'
oBtn.innerHTML = '隐藏'
// isShow = true
}
}
</script>
</body>
</html>边栏推荐
- Wincc报表教程(SQL数据库的建立,wincc在数据库中保存和查询数据,调用Excel模板把数据保存到指定的位置和打印功能)
- LayaBox---TypeScript---类
- 分账系统二清解决方案如何助力电商平台合规经营?
- 【Cloud Store Announcement】Notice of Help Center Update on July 30
- 5 个开源的 Rust Web 开发框架,你选择哪个?
- EMC VPLEX VS2 SPS电池更换详细探讨
- leetcode-684:冗余连接
- C陷阱与缺陷 第7章 可移植性缺陷 7.5 移位运算符
- JMeter Notes 4 | JMeter Interface Introduction
- Valid bracketed strings [greedy exercise]
猜你喜欢

自动化早已不是那个自动化了,谈一谈自动化测试现状和自我感受……

JVM诊断命令jcmd介绍

leetcode-684:冗余连接

知识蒸馏1:基础原理讲解及yolov5项目实战介绍

SQL行列转换

银行适用:此文能够突破你的运维流程管理问题

知识蒸馏3:YOLOV5项目准备

Mathematical Principles of Graph Convolutional Neural Networks——A Preliminary Study on Spectral Graph Theory and Fourier Transform

2022年杭电多校第2场 1001 Static Query on Tree(树链剖分+哈希表差分

分账系统二清解决方案如何助力电商平台合规经营?
随机推荐
【AGC】构建服务1-云函数示例
fast shell porting
什么是无损检测设备?
数据库系统原理与应用教程(068)—— MySQL 练习题:操作题 90-94(十二):DML 语句练习
千亿级、大规模:腾讯超大 Apache Pulsar 集群性能调优实践
数据库系统原理与应用教程(065)—— MySQL 练习题:操作题 62-70(九):分组查询与子查询
【HarmonyOS】【FAQ】鸿蒙问题合集3
Web 3.0入门教程
js中的基础知识点 —— BOM
躲避雪糕刺客?通过爬虫爬取雪糕价格
高级语言垃圾回收思路和如何减少性能影响原理分析
Wincc报表教程(SQL数据库的建立,wincc在数据库中保存和查询数据,调用Excel模板把数据保存到指定的位置和打印功能)
Moralis去中心化Web3应用开发教程
数据库系统原理与应用教程(064)—— MySQL 练习题:操作题 51-61(八):查询条件的构造、通配符
【牛客编程题】GO语言入门46题
[OC学习笔记]属性关键字
JMeter Notes 4 | JMeter Interface Introduction
[Solved] The problem that Unity Hub fails to obtain a license or does not respond and cannot develop
【网络工程】A、B、C、D、E类IP地址划分依据和特殊的IP地址
数据库系统原理与应用教程(067)—— MySQL 练习题:操作题 82-89(十一):数据的增、删、改操作