javascript - 猫头鹰旋转木马在滑动到第三项时隐藏第二项
问题描述
我已经使用URLhashListener
事件来创建水平页面滑动。
当我们从第 1页单击第 3 页按钮时,幻灯片应直接滚动到第 3页。现在它正在滑过第 2 页。
当我从第 1页转到第 3页时,如何隐藏第二页。
查看我的代码:
$('.owl-carousel').owlCarousel({
items: 1,
autoplay: false,
loop: false,
nav: false,
dots: false,
center: true,
mouseDrag: false,
touchDrag: false,
autoHeight: true,
margin: 10,
smartSpeed: 500,
URLhashListener: true,
autoplayHoverPause: true,
startPosition: 'URLHash'
});
.owl-carousel {
position: relative;
}
.page {
height: 10rem;
padding: 1rem;
height: 200px;
}
.one {
background: #bec4bd;
}
.two {
background: green;
}
.three {
background: #41253c;
}
.linkA {
position: absolute;
bottom: 10px;
left: 10px;
text-decoration: none;
background: red;
color: #fff;
padding: 5px 15px;
margin-right: 5px;
font-family: sans-serif;
font-size: 14px;
}
.linkB {
position: absolute;
bottom: 10px;
right: 10px;
text-decoration: none;
background: red;
color: #fff;
padding: 5px 15px;
margin-right: 5px;
font-family: sans-serif;
font-size: 14px;
}
<link href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet" />
<link href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.theme.default.min.css" rel="stylesheet" />
<script src="https://owlcarousel2.github.io/OwlCarousel2/assets/vendors/jquery.min.js"></script>
<script src="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/owl.carousel.js"></script>
<div class="owl-carousel owl-theme">
<div class="page one" data-hash="page1">
Button at the bottom!
<a href="#page2" class="linkA">Page 2</a>
<a href="#page3" class="linkB">Page 3</a>
</div>
<div class="page two" data-hash="page2">
Button at the bottom!
<a href="#page1" class="linkA">Page 1</a>
<a href="#page3" class="linkB">Page 3</a>
</div>
<div class="page three" data-hash="page3" style="color:#fff;">
Button at the bottom!
<a href="#page2" class="linkA">Page 2</a>
</div>
</div>
解决方案
我设法通过以下方式删除了该项目:
- 在第 1 页中添加
onclick="hidePage2();"
转到第 3 页的按钮 - 添加
hidePage2()
功能(见下文)。
但是,第 2 页在删除 (duh) 后被删除,但是当尝试使用“附加”功能或类似功能恢复它时,它会出现错误。然而,在这里你有我谦卑地想出的东西:
$('.owl-carousel').owlCarousel({
items: 1,
autoplay: false,
loop: false,
nav: false,
dots: false,
center: true,
mouseDrag: false,
touchDrag: false,
autoHeight: true,
margin: 10,
smartSpeed: 500,
URLhashListener: true,
autoplayHoverPause: true,
startPosition: 'URLHash'
});
function hidePage2(){
// from https://stackoverflow.com/a/39543557/13023528
var indexToRemove = 1;
$('.owl-carousel').owlCarousel('remove', indexToRemove).owlCarousel('update');
}
.owl-carousel {
position: relative;
}
.page {
height: 10rem;
padding: 1rem;
height: 200px;
}
.one {
background: #bec4bd;
}
.two {
background: green;
}
.three {
background: #41253c;
}
.linkA {
position: absolute;
bottom: 10px;
left: 10px;
text-decoration: none;
background: red;
color: #fff;
padding: 5px 15px;
margin-right: 5px;
font-family: sans-serif;
font-size: 14px;
}
.linkB {
position: absolute;
bottom: 10px;
right: 10px;
text-decoration: none;
background: red;
color: #fff;
padding: 5px 15px;
margin-right: 5px;
font-family: sans-serif;
font-size: 14px;
}
<link href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet" />
<link href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.theme.default.min.css" rel="stylesheet" />
<script src="https://owlcarousel2.github.io/OwlCarousel2/assets/vendors/jquery.min.js"></script>
<script src="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/owl.carousel.js"></script>
<div id="owlCarousel" class="owl-carousel owl-theme">
<div class="page one" data-hash="page1">
Button at the bottom!
<a href="#page2" class="linkA">Page 2</a>
<a href="#page3" onclick="hidePage2();" class="linkB">Page 3</a>
</div>
<div class="page two" data-hash="page2">
Button at the bottom!
<a href="#page1" class="linkA">Page 1</a>
<a href="#page3" class="linkB">Page 3</a>
</div>
<div class="page three" data-hash="page3" style="color:#fff;">
Button at the bottom!
<a href="#page2" class="linkA">Page 2</a>
</div>
</div>
编辑:哎呀错字
推荐阅读
- javascript - .Net Core API 和 PHP/JS 客户端应用程序(Syncfusion 字处理器)的 Cors 请求失败
- sql - Firebird sql从查询中删除毫秒
- c# - 我怎样才能立即将所有部分的值传给我的班级?
- sql - dbGetQuery 中的正则表达式不起作用
- groovy - 使用 Groovy 中的供应商调用 Java 方法
- elasticsearch - 带有必须和应该的 ElasticSearch 查询
- apache-kafka - 初始批量加载后未创建 Kafka 主题
- c# - 为 Autofac 中的嵌套依赖项提供类型化参数
- sqlite - 如何将从 Osquery 触发的 SQL 查询的输出保存到文件中
- html - HTML 按钮和 div 出现在导航栏上,但使用 z-index 会中断动画