html轮播底部圆点怎么做

html轮播底部圆点怎么做,第1张

首先创建一个盒子模型,利用img标签引入背景图,并为其设置相对定位利用有序列表ol,创建四个li标签,为其设置绝对定位,更改样式为无,左浮动后,利用left:50%表示相对于背景图片距左端的距离为50%,但未真正的实现居中,需利用transform标签实现真正的居中在实现居中后,随便在四个li标签中选择一个为其命名,作为轮播图中此图所在位置的实心表示,并为其设置成白色实现最终效果。

<html>

<head>

<title>图片滚动 </title>

<style>

#div1 {position:relativewidth:650pxheight:210pxoverflow:hidden}

#div2{position:absolute}

li{float:leftlist-style-type:nonepadding:5px}

img{border:none}

a{position:relative}

</style>

<script>

window.onload=function()

{

var odiv2=document.getElementById('div2')

var ali=odiv2.getElementsByTagName('li')

var aspeed=-5

odiv2.innerHTML+=odiv2.innerHTML

odiv2.style.width=ali[0].offsetWidth*ali.length+'px'

setInterval(function()

{

odiv2.style.left=odiv2.offsetLeft+aspeed+'px'

if (odiv2.offsetLeft<-odiv2.offsetWidth/2)

{

odiv2.style.left='0px'

}

},30)}

}

</script>

</head>

<body>

<div id='div1'>

<div id='div2'>

<li><a href=""><img src="1.jpg" /></a></li>

<li><a href=""><img src="2.jpg" /></a></li>

<li><a href=""><img src="3.jpg" /></a></li>

<li><a href=""><img src="4.jpg" /></a></li>

<!--这边你可以添加任意多的li,也就是你可以添加任意多的图片,使任意多的图片轮播-->

</div>

</div>

</body>

</html>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>css实现轮播图</title>

<style>

body {

margin: 0

background: #dfe

}

ul {

margin: 0

padding: 0

list-style: none

}

.my-swiper {

position: relative

width: 800px

height: 450px

margin: 100px auto

overflow: hidden

}

.swiper-list {

position: absolute

top: 0

left: 0

width: 4000px

height: 100%

overflow: hidden

animation: swiper 10s steps(1, end) infinite

transition: left 1s linear

}

.swiper-slide {

width: 800px

height: 100%

float: left

overflow: hidden

}

.swiper-slide a {

display: block

height: 100%

}

.swiper-slide img {

display: block

width: 100%

height: 100%

object-fit: cover

}

/* 分页 */

.pagination {

position: absolute

bottom: 0

left: 0

right: 0

line-height: 45px

background: rgba(255, 255, 255, 0.3)

text-align: center

}

.dot {

display: inline-block

width: 10px

height: 10px

margin: 0 2px

background: #fff

border-radius: 50%

}

/* 橙色小圆点 */

.dot.active {

position: absolute

left: 356px

top: 18px

width: 11px

height: 11px

margin: 0

background: tomato

animation: swiper-dot 10s steps(1, end) infinite

transition: left 1s linear

}

@keyframes swiper {

0%,

100% {

left: 0

}

20% {

left: -800px

}

40% {

left: -1600px

}

60% {

left: -2400px

}

80% {

left: -3200px

}

/* 100% {

left: -3200px

} */

}

@keyframes swiper-dot {

0%,

100% {

left: 358px

}

20% {

left: 376px

}

40% {

left: 395px

}

60% {

left: 413px

}

80% {

left: 432px

}

}

</style>

</head>

<body>

<div>

<ul>

<li class="swiper-slide swiper-slide1">

<a href="javascript:">

<img src="banner.jpg" alt="">

</a>

</li>

<li class="swiper-slide swiper-slide2">

<a href="javascript:">

<img src="banner1.jpg" alt="">

</a>

</li>

<li class="swiper-slide swiper-slide3">

<a href="javascript:">

<img src="banner2.jpg" alt="">

</a>

</li>

<li class="swiper-slide swiper-slide4">

<a href="javascript:">

<img src="banner.jpg" alt="">

</a>

</li>

<li class="swiper-slide swiper-slide5">

<a href="javascript:">

<img src="banner1.jpg" alt="">

</a>

</li>

</ul>

<div>

<span></span>

<span></span>

<span></span>

<span></span>

<span></span>

<span class="dot active"></span>

</div>

</div>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7460249.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-05
下一篇 2023-04-05

发表评论

登录后才能评论

评论列表(0条)

保存