gpt4 book ai didi

javascript - css-如何向图像添加动态 slider ?

转载 作者:行者123 更新时间:2023-12-02 21:24:23 24 4
gpt4 key购买 nike

我创建了一个动态布局,它从我的 banner 表中检索图片并显示在 View 页面上。我已经在我的 laravel 元素上设置了模型和 Controller 。它看起来像下面这样:

enter image description here

它检索 2 张图片,但将其堆叠在另一张下面。我想知道是否有一种方法可以将其设置为 slider ,即第一张图片将向左/向右滑动并自动更改为第二张图片,依此类推。

我的代码:

<!-- Banner Area Start -->
<section class="hero-area">

<div class="hero-area-slider">

<!--class for display banner -->
<div class="intro-carousel">
@foreach($data as $pic)
<div class="intro-content" style="background-image: url({{asset('/images/'.$pic->photo)}})">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="slider-content">
</div>
</div>
</div>
</div>

</div>
@endforeach
</div>
</section>
<br>

风格:

/*-----------------------------
** Banner Area Start
------------------------------*/



.hero-area .hero-area-slider .intro-carousel .intro-content {
background-size: cover;
height: 500px;

display: flex;
align-items: center;
background-position: center !important;
background-size: cover !important;
background-repeat: no-repeat !important;

margin-top: 10px;
margin-left: 80px;
margin-right: 80px;
}
.hero-area .hero-area-slider .intro-carousel .intro-content.slide-one {
text-align: left; }
.hero-area .hero-area-slider .intro-carousel .intro-content.slide-two {
text-align: center; }
.hero-area .hero-area-slider .intro-carousel .intro-content.slide-three {
text-align: right; }

.hero-area .hero-area-slider .intro-carousel .intro-content .slider-content .layer-1 .subtitle {
font-size: 24px;
font-weight: 700;
color: #143250;
}
.hero-area .hero-area-slider .intro-carousel .intro-content .slider-content .layer-1 .title {
font-size: 36px;
font-weight: 700;
color: #ff5500;
}

.hero-area .hero-area-slider .intro-carousel .intro-content .slider-content .layer-2 .text {
font-size: 16px;
font-weight: 600;
color: #143250;
max-width: 400px;
display: inline-block; }

.hero-area .hero-area-slider .intro-carousel .intro-content .slider-content .layer-3 a {
margin-top: 15px;
text-align: center;
border: 1px solid #ff5500;
}
.hero-area .hero-area-slider .intro-carousel .intro-content .slider-content .layer-3 a:hover {
background: #fff;
color: #ff5500;
}

.hero-area .hero-area-slider .intro-carousel .intro-content .slider-content .layer-3 a i{
font-size: 13px;}


/* hero Slider dot design Start */

.hero-area .hero-area-slider .owl-controls .owl-dots {
display: block;
position: absolute;
text-align: center;
margin-top: 0px;
left: 50%;
transform: translateX(-50%);
bottom: 20px;
}
.hero-area .hero-area-slider .owl-controls .owl-dots .owl-dot {
width: 25px;
height: 6px;
background: #fff;
display: inline-block;
border-radius: 0px;
transform: skewX(-30deg);
margin: 0px 3px 0px;
-webkit-transition: 0.3s ease-in;
-moz-transition: 0.3s ease-in;
-o-transition: 0.3s ease-in;
transition: 0.3s ease-in;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1);
}
.hero-area .hero-area-slider .owl-controls .owl-dots .owl-dot.active {
background: #fff;
width: 50px
}

.blog-area .aside .slider-wrapper .owl-controls .owl-dots {
display: block;
text-align: center;
margin-top: -1px; }
.blog-area .aside .slider-wrapper .owl-controls .owl-dots .owl-dot {
width: 10px;
height: 10px;
background: #c2c2c2;
display: inline-block;
border-radius: 50%;
margin: 0px 3px 0px;
-webkit-transition: 0.3s ease-in;
-moz-transition: 0.3s ease-in;
-o-transition: 0.3s ease-in;
transition: 0.3s ease-in; }
.blog-area .aside .slider-wrapper .owl-controls .owl-dots .owl-dot.active {
background: #ff5500;
-webkit-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2); }

我想知道是否可以添加 slider ,我也可以使用鼠标并向左或向右单击/拖动,以便更改图片。谢谢

最佳答案

我希望这有帮助?

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {box-sizing: border-box}
body {font-family: Verdana, sans-serif; margin:0}
.mySlides {display: none}
img {vertical-align: middle;}

/* Slideshow container */
.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
}

/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -22px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}

/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}

/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}

/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}

/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}

/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}

.active, .dot:hover {
background-color: #717171;
}

/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}

@-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}

@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}

/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
.prev, .next,.text {font-size: 11px}
}
</style>
</head>
<body>

<div class="slideshow-container">

<div class="mySlides fade">
<div class="numbertext">1 / 3</div>
<!-- ad your picture url between the " " quotes -->
<img src=" " style="width:100%">
<div class="text">Picture 1</div>
</div>

<div class="mySlides fade">
<div class="numbertext">2 / 3</div>
<!-- ad your picture url between the " " quotes -->
<img src=" " style="width:100%">
<div class="text">Picture 2</div>
</div>

<div class="mySlides fade">
<div class="numbertext">3 / 3</div>
<!-- ad your picture url between the " " quotes -->
<img src=" " style="width:100%">
<div class="text">Picture 3</div>
</div>

<a class="prev" onclick="plusSlides(-1)">&#10094;</a>
<a class="next" onclick="plusSlides(1)">&#10095;</a>

</div>
<br>

<div style="text-align:center">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>

<script>
var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
showSlides(slideIndex += n);
}

function currentSlide(n) {
showSlides(slideIndex = n);
}

function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
</script>

</body>
</html>

关于javascript - css-如何向图像添加动态 slider ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60774326/

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