1 回答
TA贡献1820条经验 获得超10个赞
对于解决方案,我必须对 css、html 进行一些更改并修复 js 代码以确定活动幻灯片。
这样的结果有必要吗?
var carousel = $(".carousel"),
currdeg = 0,
current = 0;
$(".next").on("click", {d: "n"}, rotate);
$(".prev").on("click", {d: "p"}, rotate);
function rotate(e) {
$(carousel.find('.active')).removeClass('active');
if (e.data.d == "n") {
currdeg = currdeg - 120;
current = (current + 1) % carousel.find('.item').length;
}
if (e.data.d == "p") {
currdeg = currdeg + 120;
current = (current - 1 + carousel.find('.item').length) % carousel.find('.item').length;
}
$(carousel.find('.item')[current]).addClass('active');
carousel.css({
"-webkit-transform": "rotateY(" + currdeg + "deg)",
"-moz-transform": "rotateY(" + currdeg + "deg)",
"-o-transform": "rotateY(" + currdeg + "deg)",
"transform": "rotateY(" + currdeg + "deg)"
});
}
.container {
margin: -100px auto;
width: 250px;
height: 200px;
position: relative;
top: 500px;
perspective: 1000px;
}
.carousel {
height: 100%;
width: 100%;
position: absolute;
transform-style: preserve-3d;
transition: transform 1s;
}
.item {
display: block;
position: absolute;
background: #000;
width: 250px;
height: 200px;
line-height: 200px;
font-size: 5em;
text-align: center;
color: #FFF;
/*opacity: 0.95;*/
}
.item.active {
cursor: pointer;
}
.a {
transform: rotateY(0deg) translateZ(250px);
}
.b {
transform: rotateY(120deg) translateZ(250px);
}
.c {
transform: rotateY(240deg) translateZ(250px);
}
.next, .prev {
color: #444;
position: absolute;
top: 500px;
padding: 1em 2em;
cursor: pointer;
background: #CCC;
border-radius: 5px;
border-top: 1px solid #FFF;
box-shadow: 0 5px 0 #999;
transition: box-shadow 0.1s, top 0.1s;
}
.next:hover, .prev:hover { color: #000; }
.next:active, .prev:active {
top: 504px;
box-shadow: 0 1px 0 #999;
}
.next { right: 5em; }
.prev { left: 5em; }
.content {
position: relative;
width: 100%;
margin-left: auto;
margin-right: auto;
max-width: 400px;
}
.container .title{
color: #1a1a1a;
text-align: center;
margin-bottom: 10px;
}
.carousel .content-overlay,
.content .content-overlay {
background: rgba(0,0,0,0.7);
position: absolute;
height: 100%;
width: 100%;
opacity: 0;
-webkit-transition: all 0.4s ease-in-out 0s;
-moz-transition: all 0.4s ease-in-out 0s;
transition: all 0.4s ease-in-out 0s;
}
.content:hover .content-overlay{
opacity: 1;
}
.carousel .item.active:hover .content-overlay{
opacity: 1;
}
.content-image{
width: 100%;
}
.content-details {
position: absolute;
text-align: center;
padding-left: 1em;
padding-right: 1em;
width: 100%;
top: 50%;
left: 50%;
opacity: 0;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: all 0.3s ease-in-out 0s;
-moz-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
.content:hover .content-details{
top: 50%;
left: 50%;
opacity: 1;
}
.content-details h3{
color: #fff;
font-weight: 500;
letter-spacing: 0.15em;
margin-bottom: 0.5em;
text-transform: uppercase;
}
.content-details p{
color: #fff;
font-size: 0.8em;
}
.fadeIn-bottom{
top: 80%;
}
.content {
position: relative;
width: 100%;
margin-left: auto;
margin-right: auto;
max-width: 400px;
}
.content .content-overlay {
background: rgba(0,0,0,0.7);
position: absolute;
height: 99%;
width: 100%;
opacity: 0;
-webkit-transition: all 0.4s ease-in-out 0s;
-moz-transition: all 0.4s ease-in-out 0s;
transition: all 0.4s ease-in-out 0s;
}
.content:hover .content-overlay{
opacity: 1;
}
.content-image{
width: 100%;
}
.content-details {
position: absolute;
text-align: center;
padding-left: 1em;
padding-right: 1em;
width: 100%;
top: 50%;
left: 50%;
opacity: 0;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: all 0.3s ease-in-out 0s;
-moz-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
.content:hover .content-details{
top: 50%;
left: 50%;
opacity: 1;
}
.content-details h3{
color: #fff;
font-weight: 500;
letter-spacing: 0.15em;
margin-bottom: 0.5em;
text-transform: uppercase;
}
.content-details p{
color: #fff;
font-size: 0.8em;
}
.fadeIn-bottom{
top: 80%;
}
.carousel_content-details {
position: absolute;
text-align: center;
width: 100%;
top: 50%;
left: 50%;
opacity: 0;
margin: 0;
padding: 0;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-webkit-transition: all 0.3s ease-in-out 0s;
-moz-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
.carousel .item.active:hover .carousel_content-details{
top: 50%;
left: 50%;
opacity: 1;
}
.carousel_content-details h3{
color: #fff;
font-size: 24px;
font-weight: 500;
letter-spacing: 0.15em;
margin-bottom: 0.5em;
text-transform: uppercase;
margin: 0;
padding: 0;
}
.carousel_fadeIn-bottom{
top: 50%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="style.css" rel="stylesheet" type="text/css">
<title>Document</title>
</head>
<body>
<div class="content">
<a href="#open-modal">
<div class="content-overlay"></div>
<img class="content-image" src="https://static.independent.co.uk/s3fs-public/thumbnails/image/2014/03/25/12/eiffel.jpg">
<div class="content-details fadeIn-bottom">
<h3 class="content-title">Eiffel Tower</h3>
</div>
</a>
</div>
<div class="container">
<div class="carousel">
<div class="item a active">
<div class="content-overlay"></div>
<img src="https://www.insidehook.com/wp-content/uploads/2019/08/HERO-3.jpg?fit=1200%2C750" width="250px" height="200px">
<div class="carousel_content-details carousel_fadeIn-bottom">
<h3 class="carousel_content-title">Text 1</h3>
</div>
</div>
<div class="item b">
<div class="content-overlay"></div>
<img src="https://static.independent.co.uk/s3fs-public/thumbnails/image/2014/03/25/12/eiffel.jpg" width="250px" height="200px">
<div class="carousel_content-details carousel_fadeIn-bottom">
<h3 class="carousel_content-title">Text 2</h3>
</div>
</div>
<div class="item c">
<div class="content-overlay"></div>
<img src="https://nypost.com/wp-content/uploads/sites/2/2019/12/robberies-serious-crimes-spike-in-central-park-this-year.jpg?quality=80&strip=all" width="250px" height="200px">
<div class="carousel_content-details carousel_fadeIn-bottom">
<h3 class="carousel_content-title">Text 3</h3>
</div>
</div>
</div>
</div>
<div class="next">Next</div>
<div class="prev">Prev</div>
<script src="script.js"></script>
</body>
</html>
添加回答
举报