gpt4 book ai didi

javascript - 当我将它插入网站时,为什么这个 slider 不起作用?

转载 作者:太空宇宙 更新时间:2023-11-04 08:23:03 26 4
gpt4 key购买 nike

我从 codepen.io 中挑选了一个 slider 放在我的网站上,但当我嵌入它时它不起作用......应该分开的四个幻灯片都在一起并且按钮不起作用。 .. 当我将代码粘贴到 JSFiddle 中时,也会发生同样的情况...有人能帮帮我吗?

这是 fiddle :https://jsfiddle.net/swpch979/这是代码:

<div class="slider">
<input class="slider__nav" type="radio" name="slider" title="slide1" checked="checked"/>
<input class="slider__nav" type="radio" name="slider" title="slide2"/>
<input class="slider__nav" type="radio" name="slider" title="slide3"/>
<input class="slider__nav" type="radio" name="slider" title="slide4"/>
<div class="slider__inner">
<div class="slider__contents"><i class="slider__image fa fa-codepen"></i>
<h2 class="slider__caption">codepen</h2>
<p class="slider__txt">Lorem ipsum dolor sit amet, consectetur adipisicing elit. At cupiditate omnis possimus illo quos, corporis minima!</p>
</div>
<div class="slider__contents"><i class="slider__image fa fa-newspaper-o"></i>
<h2 class="slider__caption">newspaper-o</h2>
<p class="slider__txt">Lorem ipsum dolor sit amet, consectetur adipisicing elit. At cupiditate omnis possimus illo quos, corporis minima!</p>
</div>
<div class="slider__contents"><i class="slider__image fa fa-television"></i>
<h2 class="slider__caption">television</h2>
<p class="slider__txt">Lorem ipsum dolor sit amet, consectetur adipisicing elit. At cupiditate omnis possimus illo quos, corporis minima!</p>
</div>
<div class="slider__contents"><i class="slider__image fa fa-diamond"></i>
<h2 class="slider__caption">diamond</h2>
<p class="slider__txt">Lorem ipsum dolor sit amet, consectetur adipisicing elit. At cupiditate omnis possimus illo quos, corporis minima!</p>
</div>
</div>
</div>
<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=Josefin+Sans:400,700);
@import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css);

$slider-length: 4;
$radioBtn-size: 12px;
$btn-color: #ccc;
$active-color: #333;
//---------------------------------------------------

*, *:before, *:after { box-sizing: border-box;}

html,body { height: 100%;}

body {
color: #444;
font-family: 'Josefin Sans', sans-serif;
font-size: 1rem;
line-height: 1.5;
}

.slider {
height: 100%;
position: relative;
overflow: hidden;
display: flex;
flex-flow: row nowrap;
align-items: flex-end;
justify-content: center;

&__nav {
width: $radioBtn-size;
height: $radioBtn-size;
margin: 2rem $radioBtn-size;
border-radius: 50%;
z-index: 10;
outline: $radioBtn-size / 2 solid $btn-color;
outline-offset: $radioBtn-size / -2;
box-shadow:
0 0 0 0 $active-color,
0 0 0 0 rgba($active-color,0);
cursor: pointer;
appearance: none;
backface-visibility: hidden;

&:checked {
animation: check 0.5s linear forwards;

@for $i from 0 to $slider-length {
&:nth-of-type(#{$i+1}) {
~ .slider__inner {
transform: translateX((-100% * $i) / $slider-length);
}
}
}
}
}

&__inner {
position: absolute;
top: 0;
left: 0;
width: 100% * $slider-length;
height: 100%;
transition: all 1s ease-out;
display: flex;
flex-flow: row nowrap;
}

&__contents {
height: 100%;
padding: 2rem;
text-align: center;
display: flex;
flex: 1;
flex-flow: column nowrap;
align-items: center;
justify-content: center;
}

&__image {
font-size: 2.7rem;
}

&__caption {
font-weight: 700;
margin: 2rem 0 1rem;
text-shadow: 0 1px 1px rgba(0,0,0,0.1);
text-transform: uppercase;
}

&__txt {
color: #999;
margin-bottom: 3rem;
max-width: 300px;
}
}



// animation ---------------------------

@keyframes check {
50% {
outline-color: $active-color;
box-shadow:
0 0 0 $radioBtn-size $active-color,
0 0 0 $radioBtn-size*3 rgba($active-color,0.2);
}
100% {
outline-color: $active-color;
box-shadow:
0 0 0 0 $active-color,
0 0 0 0 rgba($active-color,0);
}
}

谢谢,

汤姆

最佳答案

它使用 scss 作为预处理器。转换为常规 CSS 即可。

@import url(https://fonts.googleapis.com/css?family=Josefin+Sans:400,700);
@import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css);
*,
*:before,
*:after {
box-sizing: border-box;
}

html,
body {
height: 100%;
}

body {
color: #444;
font-family: 'Josefin Sans', sans-serif;
font-size: 1rem;
line-height: 1.5;
}

.slider {
height: 100%;
position: relative;
overflow: hidden;
display: flex;
flex-flow: row nowrap;
align-items: flex-end;
justify-content: center;
}

.slider__nav {
width: 12px;
height: 12px;
margin: 2rem 12px;
border-radius: 50%;
z-index: 10;
outline: 6px solid #ccc;
outline-offset: -6px;
box-shadow: 0 0 0 0 #333, 0 0 0 0 rgba(51, 51, 51, 0);
cursor: pointer;
appearance: none;
backface-visibility: hidden;
}

.slider__nav:checked {
animation: check 0.5s linear forwards;
}

.slider__nav:checked:nth-of-type(1)~.slider__inner {
transform: translateX(0%);
}

.slider__nav:checked:nth-of-type(2)~.slider__inner {
transform: translateX(-25%);
}

.slider__nav:checked:nth-of-type(3)~.slider__inner {
transform: translateX(-50%);
}

.slider__nav:checked:nth-of-type(4)~.slider__inner {
transform: translateX(-75%);
}

.slider__inner {
position: absolute;
top: 0;
left: 0;
width: 400%;
height: 100%;
transition: all 1s ease-out;
display: flex;
flex-flow: row nowrap;
}

.slider__contents {
height: 100%;
padding: 2rem;
text-align: center;
display: flex;
flex: 1;
flex-flow: column nowrap;
align-items: center;
justify-content: center;
}

.slider__image {
font-size: 2.7rem;
}

.slider__caption {
font-weight: 700;
margin: 2rem 0 1rem;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
text-transform: uppercase;
}

.slider__txt {
color: #999;
margin-bottom: 3rem;
max-width: 300px;
}

@keyframes check {
50% {
outline-color: #333;
box-shadow: 0 0 0 12px #333, 0 0 0 36px rgba(51, 51, 51, 0.2);
}
100% {
outline-color: #333;
box-shadow: 0 0 0 0 #333, 0 0 0 0 rgba(51, 51, 51, 0);
}
}
<div class="slider">
<input class="slider__nav" type="radio" name="slider" title="slide1" checked="checked" />
<input class="slider__nav" type="radio" name="slider" title="slide2" />
<input class="slider__nav" type="radio" name="slider" title="slide3" />
<input class="slider__nav" type="radio" name="slider" title="slide4" />
<div class="slider__inner">
<div class="slider__contents"><i class="slider__image fa fa-codepen"></i>
<h2 class="slider__caption">codepen</h2>
<p class="slider__txt">Lorem ipsum dolor sit amet, consectetur adipisicing elit. At cupiditate omnis possimus illo quos, corporis minima!</p>
</div>
<div class="slider__contents"><i class="slider__image fa fa-newspaper-o"></i>
<h2 class="slider__caption">newspaper-o</h2>
<p class="slider__txt">Lorem ipsum dolor sit amet, consectetur adipisicing elit. At cupiditate omnis possimus illo quos, corporis minima!</p>
</div>
<div class="slider__contents"><i class="slider__image fa fa-television"></i>
<h2 class="slider__caption">television</h2>
<p class="slider__txt">Lorem ipsum dolor sit amet, consectetur adipisicing elit. At cupiditate omnis possimus illo quos, corporis minima!</p>
</div>
<div class="slider__contents"><i class="slider__image fa fa-diamond"></i>
<h2 class="slider__caption">diamond</h2>
<p class="slider__txt">Lorem ipsum dolor sit amet, consectetur adipisicing elit. At cupiditate omnis possimus illo quos, corporis minima!</p>
</div>
</div>
</div>

关于javascript - 当我将它插入网站时,为什么这个 slider 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45400487/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com