当前位置:网站首页>简单的轮播图
简单的轮播图
2022-07-27 06:10:00 【猿码当先】
html部分
<body>
<div class="foucs" onmouseover="end()" onmouseout="start()">
<div id="imgs">
<img src="./img/1.jpg" />
<img src="./img/2.jpg" />
<img src="./img/3.jpg" />
<img src="./img/4.jpg" />
<img src="./img/5.jpg" />
</div>
<div class="nav">
<ul id="list">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
<h1 id="left" onclick="left()"><</h1>
<h1 id="right" onclick="right()">></h1>
</div>
</body>css样式段
<style>
*{
margin: 0;
padding: 0;
}
div.foucs{
position: relative;
}
div.foucs:hover{
cursor: pointer;
}
div.foucs h1{
position: absolute;
font-size: 50px;
}
div.foucs h1#left{
top: 150px;
}
div.foucs h1#right{
top: 150px;
right: 10px;
}
div.foucs img{
width: 100%;
height: 350px;
display: none;
}
ul{
list-style: none;
position: absolute;
bottom: 10%;
left: 30%;
/* background-color: brown; */
}
ul li{
display: inline-block;
width: 30px;
height: 30px;
line-height: 30px;
text-align: center;
margin: 0 30px;
background-color: darkgrey;
border-radius: 50%;
}
</style>js部分
<script>
let i = 0;
function demo(){
let imgs = document.getElementById("imgs").children;
let list = document.getElementById("list").children;
for(let n =0;n<imgs.length;n++){
imgs[n].style = "display:none";
list[n].style = "background-color:darkgrey";
}
imgs[i].style = "display:block";
list[i].style = "background-color:red";
i++;
if(i==imgs.length){
i=0;
}
}
demo();
let interval = setInterval(demo,3000);
function end(){
clearInterval(interval);
}
function start(){
interval = setInterval(demo,3000);
}
let j = 0;
let list = document.getElementById("list").children;
while(j<list.length){
list[j].index = j;
list[j].onmouseover = function(){
i = this.index;
demo();
}
j++;
}
function left(){
let imgs = document.getElementById("imgs").children;
if(i==1){
i = imgs.length - 1;
}else if(i==0){
i = imgs.length-2;
}else{
i-=2;
}
// i-=2;
demo();
}
function right(){
demo();
}
</script>可以自动轮播照片,可以点击导航切换,可以点击左右按钮切换,鼠标悬停在图片上时,停止轮播,离开后继续播放
边栏推荐
- 多线程【初阶-上篇】
- Vscode creates golang development environment and debug unit test of golang
- TS learning (VIII): classes in TS
- MySQL optimization SQL related (continuous supplement)
- 内部类--看这篇就懂啦~
- [Vani有约会]雨天的尾巴
- Working principle analysis of deepsort
- C4D动画如何提交云渲染农场快速渲染?
- 用typescript实现排序-递增
- "Weilai Cup" 2022 Niuke summer multi school training camp 1
猜你喜欢

How to submit C4d animation to cloud rendering farm for fast rendering?

Synchronized锁

How to implement Devops with automation tools | including low code and Devops application practice

多线程【初阶-上篇】

Relevant principles of MySQL index optimization

美联储SR 11-7:模型风险管理指南(Guidance on Model Risk Management)-万字收藏

Jmeter: interface automation test - BeanShell compares database data and return data

软件测试十大必问面试题(附答案和解析)

Perl: 将要执行的外部命令拆分为多行

Overall dichotomy?
随机推荐
使用pip命令切换不同的镜像源
Codeforces Round #804 (Div. 2)(5/5)
Usage of string class
Quartus:往别人的工程添加.v文件报错
Zabbix: 将收集到值映射为易读的语句
Drools (5): drools advanced syntax
Watermelon book learning Chapter 5 --- neural network
Automatically generate UML sequence diagram according to text (draw.io format)
Which C4d cloud rendering platform to cooperate with?
[Vani有约会]雨天的尾巴
oracle的触发器的使用举例
Py2exe QT interface style becomes Win98 solution
(posted) comparison of Eureka, consumer and Nacos 2
A Competitive Swarm Optimizer for Large Scale Optimization
pre-commit install 时 CalledProcessError
Tableau prep is connected to maxcompute and only writes simple SQL. Why is this error reported?
高级IO提纲
Internal class -- just read this article~
Common problems in converting pytorch to onnx
在rhel8上使用soci连接oracle和postgresql和sqlite