作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个任务要写slider
包含有关上一个和下一个 slider 的信息。
例如在 slider 中你离开了<
和对>
箭头后面有一个圆圈 此圈子中的这张(上一张或下一张)图像来自数据属性,灵感来自 this carousel
除了从关于 prev
的数据属性中获取信息外,我意识到了一切或 next
图片。
请帮帮我。
$(function () {
var $owl = $('.owl-carousel'),
isDragged = false;
$owl.owlCarousel({
margin: 0,
navSpeed: 500,
nav: true,
items: 1,
navText : ["<img src='https://cdn4.iconfinder.com/data/icons/arrows-9/100/arrow-9-512.png'><span></span>","<img src='http://pixsector.com/cache/81183b13/avcc910c4ee5888b858fe.png'><span></span>"]
});
});
.owl-carousel {
position: relative;
top: -65px;
}
.owl-carousel .item {
position: relative;
height: 816px;
}
.owl-carousel .item img {
position: absolute;
height: 816px;
width: 100vw !important;
}
.owl-carousel .owl-prev:hover span {
max-width: 200px;
padding: 5px 5px 0 25px;
background: #fbfbfb;
height: 15px;
margin-top: -1.3rem;
font-size: 15px;
}
@media only screen and (max-width: 768px) {
.owl-carousel .owl-prev:hover span {
margin-top: -1rem;
}
}
.owl-carousel .owl-prev:hover span:before {
width: 10px;
height: 10px;
top: 1.5px;
left: 2px;
}
.owl-carousel .owl-prev img {
left: 1%;
}
.owl-carousel .owl-prev span {
top: 50%;
left: 3.5%;
}
@media only screen and (max-width: 992px) {
.owl-carousel .owl-prev span {
left: 5%;
}
}
@media only screen and (max-width: 768px) {
.owl-carousel .owl-prev span {
top: 48.5%;
}
}
.owl-carousel .owl-prev span:before {
right: -15px;
}
.owl-carousel .owl-next:hover span {
max-width: 200px;
padding: 5px 5px 0 25px;
background: #fbfbfb;
height: 15px;
margin-top: -1.3rem;
font-size: 15px;
}
@media only screen and (max-width: 768px) {
.owl-carousel .owl-next:hover span {
margin-top: -1rem;
}
}
.owl-carousel .owl-next:hover span:before {
width: 10px;
height: 10px;
top: 1.5px;
left: 17px;
}
.owl-carousel .owl-next img {
right: 1%;
}
.owl-carousel .owl-next span {
top: 50%;
right: 3.5%;
}
@media only screen and (max-width: 992px) {
.owl-carousel .owl-next span {
right: 5%;
}
}
@media only screen and (max-width: 768px) {
.owl-carousel .owl-next span {
top: 48.5%;
}
}
.owl-carousel .owl-next span:before {
right: -15px;
}
.owl-carousel .owl-prev img, .owl-carousel .owl-next img {
position: absolute;
top: 45%;
height: 7%;
}
@media only screen and (max-width: 768px) {
.owl-carousel .owl-prev img, .owl-carousel .owl-next img {
height: 5%;
}
}
.owl-carousel .owl-prev span, .owl-carousel .owl-next span {
border: 1px solid #fff;
float: left;
border-radius: 100rem;
height: 5px;
padding: 5px;
cursor: pointer;
max-width: 0;
overflow: hidden;
position: absolute;
margin-top: -1.3rem;
white-space: nowrap;
line-height: 0;
transition: padding 0.2s linear, max-width 0.2s linear;
-webkit-transition: padding 0.2s linear, max-width 0.2s linear;
}
@media only screen and (max-width: 768px) {
.owl-carousel .owl-prev span, .owl-carousel .owl-next span {
margin-top: -1rem;
}
}
.owl-carousel .owl-prev span:before, .owl-carousel .owl-next span:before {
content: '';
display: block;
position: absolute;
width: 0;
height: 0;
background: #bebebe;
border-radius: 100rem;
top: 0;
transition: all 0.3s linear;
-webkit-transition: all 0.3s linear;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.0.0-beta.3/assets/owl.carousel.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/owl.carousel.min.js"></script>
<div class="owl-carousel">
<div class="item" date-text="witcher"><img src="https://nerdist.com/wp-content/uploads/2017/05/the-witcher-featured-image-970x545.jpg"> </div>
<div class="item" date-text="bulbasaur"><img src="https://dingo.care2.com/pictures/petition_images/petition/685/852582-1505568504-wide.jpg"> </div>
<div class="item" date-text="t-rex"><img src="https://i.redd.it/mkzm86rrnso01.jpg"> </div>
<div class="item" date-text="math"><img src="http://bsnscb.com/data/out/124/38995301-maths-wallpapers.png"> </div>
<div class="item" date-text="girl"><img src="http://globalmedicalco.com/photos/globalmedicalco/23/112016.jpg"> </div>
<div class="item" date-text="linux"><img src="https://cn.pling.com/img/f/2/e/7/5fa66423c18fcdf85af6c318d82bae08ad22.png"> </div>
</div>
最佳答案
只需要添加这段jQuery
代码,并将类名添加到span
$(document).ready(function () {
$(".owl-prev").hover(function () {
$(".data-text").html($(".owl-item.active").prev().find(".item").attr("data-text"));
})
$(".owl-prev").on("click", function () {
$(".data-text").html($(".owl-item.active").prev().find(".item").attr("data-text"));
})
$(".owl-next").hover(function () {
$(".data-text").html($(".owl-item.active").next().find(".item").attr("data-text"));
})
$(".owl-next").on("click", function () {
$(".data-text").html($(".owl-item.active").next().find(".item").attr("data-text"));
})
});
关于javascript - 从数据属性获取有关上一个和下一个 slider 的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51225869/
我是一名优秀的程序员,十分优秀!