Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js] 第36天 请手写一个幻灯片的效果 #134

Open
haizhilin2013 opened this issue May 21, 2019 · 8 comments
Open

[js] 第36天 请手写一个幻灯片的效果 #134

haizhilin2013 opened this issue May 21, 2019 · 8 comments
Labels
js JavaScript

Comments

@haizhilin2013
Copy link
Collaborator

第36天 请手写一个幻灯片的效果
注:可以使用纯css

@haizhilin2013 haizhilin2013 added the js JavaScript label May 21, 2019
@AnsonZnl
Copy link
Contributor

使用css3 动画就可以,预览地址:https://codepen.io/ansonznl/pen/KLyJjX

@haizhilin2013
Copy link
Collaborator Author

@AnsonZnl 不错,可以再用js再写个,呵呵

@tzjoke
Copy link

tzjoke commented May 28, 2019

js的思路可以是设置元素className来切换

@myprelude
Copy link

myprelude commented Jun 13, 2019

你这个是难为我胖虎啊 @haizhilin2013
面试那么长时间写个这个也是有点麻烦 考虑的比较多,简单说下思路还是ok的,
思路一 元素并排浮动 改变offset
思路二 position 层叠 改变z-Index

@Konata9
Copy link

Konata9 commented Sep 1, 2019

不算很好的实现,先占个楼。

https://codepen.io/Konata9/pen/GRKvxjx?editors=0111

@seho-dev
Copy link

seho-dev commented Sep 3, 2019

.box > .main > .swiper > .swiperList {
position: absolute;
display: flex;
width: 3500px;
height: 270px;
animation: 20s swiper infinite; /循环/
}
.swiper > .swiperList > li {
width: 625px;
height: 270px;
}
.box > .main > .swiper > .swiperList > li:first-child {
background: url(images/banner.jpg) no-repeat center center / 100% 100%;
}
.box > .main > .swiper > .swiperList > li:nth-child(2) {
background: url(images/banner.jpg) no-repeat center center / 100% 100%;
}
.box > .main > .swiper > .swiperList > li:nth-child(3) {
background: url(images/banner.jpg) no-repeat center center / 100% 100%;
}
.box > .main > .swiper > .swiperList > li:nth-child(4) {
background: url(images/banner.jpg) no-repeat center center / 100% 100%;
}
.box > .main > .swiper > .swiperList > li:nth-child(5) {
background: url(images/banner.jpg) no-repeat center center / 100% 100%;
}

/动画/
@Keyframes swiper {
0% {
left: 0px;
}

12% {
left: 0px;
}

25% {
left: -625px;
}

37% {
left: -625px;
}

50% {
left: -1250px;
}

62% {
left: -1250px;
}

75% {
left: -1875px;
}

87% {
left: -1875px;
}

100% {
left: -2500px;
}
}

@jamsehua
Copy link

.box > .main > .swiper > .swiperList {
position: absolute;
display: flex;
width: 3500px;
height: 270px;
animation: 20s swiper infinite; /循环/
}
.swiper > .swiperList > li {
width: 625px;
height: 270px;
}
.box > .main > .swiper > .swiperList > li:first-child {
background: url(images/banner.jpg) no-repeat center center / 100% 100%;
}
.box > .main > .swiper > .swiperList > li:nth-child(2) {
background: url(images/banner.jpg) no-repeat center center / 100% 100%;
}
.box > .main > .swiper > .swiperList > li:nth-child(3) {
background: url(images/banner.jpg) no-repeat center center / 100% 100%;
}
.box > .main > .swiper > .swiperList > li:nth-child(4) {
background: url(images/banner.jpg) no-repeat center center / 100% 100%;
}
.box > .main > .swiper > .swiperList > li:nth-child(5) {
background: url(images/banner.jpg) no-repeat center center / 100% 100%;
}

/动画/
@Keyframes swiper {
0% {
left: 0px;
}

12% {
left: 0px;
}

25% {
left: -625px;
}

37% {
left: -625px;
}

50% {
left: -1250px;
}

62% {
left: -1250px;
}

75% {
left: -1875px;
}

87% {
left: -1875px;
}

100% {
left: -2500px;
}
}

c3整的挺6

@HoseaGuo
Copy link

HoseaGuo commented Aug 22, 2022

  1. 利用 animation-timing-function 的 steps
    https://codepen.io/hoseaguo/pen/NWYJbQr

  2. 纯css无限轮播,鼠标悬停动画停止
    https://codepen.io/hoseaguo/pen/OJvqGGw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js JavaScript
Projects
None yet
Development

No branches or pull requests

8 participants