- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为 Slick Carousel (latest version) 添加下一个和上一个箭头有条件地当内容占用比外部容器更多的空间时( <div class="container">
)。
例子:
目标:
这是我的设置,但有条件地添加箭头不起作用。
$(function() {
$('.carousel').slick({
focusOnSelect: true,
arrows: true,
infinite: false,
variableWidth: true,
prevArrow: '<div class="prev-arrow"><i class="fa fa-angle-left fa-2x" aria-hidden="true"></i></div>',
nextArrow: '<div class="next-arrow"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></div>',
});
});
.carousel {
color: black;
display: block;
}
.carousel .item {
border: 1px solid white;
margin: 0 10px;
padding: 5px;
}
.slick-list {
width: auto;
margin: 0 auto;
height: auto;
}
.item.slick-current {
border-bottom: 2px solid black;
}
.prev-arrow {
position: absolute;
left: 0;
top: 0;
z-index: 10;
}
.next-arrow {
position: absolute;
right: 0;
z-index: 10;
top: 0;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick-theme.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="carousel">
<div class="item">
tab 1
</div>
<div class="item">
tab 2
</div>
<div class="item">
tab 3
</div>
<div class="item">
tab 4
</div>
<div class="item">
tab 5
</div>
<div class="item">
tab 6
</div>
</div>
</div>
</div>
</div>
当前输出:
最佳答案
我找到了这个问题的答案。
$(function() {
$('.carousel').slick({
focusOnSelect: true,
arrows: true,
infinite: false,
variableWidth: true,
slidesToShow: 5,
prevArrow: '<div class="prev-arrow"><i class="fa fa-angle-left fa-2x" aria-hidden="true"></i></div>',
nextArrow: '<div class="next-arrow"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></div>',
});
var childrenWidth = 0;
$('.carousel .slick-track').children().each(function() {
childrenWidth += $(this).width();
});
var outerContainerWidth = $('.carousel').width();
if(childrenWidth < outerContainerWidth) {
var nextArrow = $('.next-arrow');
if(!(nextArrow.hasClass('slick-disabled'))) {
nextArrow.addClass('slick-disabled');
}
}
});
.carousel {
color: black;
display: block;
}
.carousel .item {
border: 1px solid white;
margin: 0 10px;
padding: 5px;
}
.slick-list {
width: auto;
margin: 0 auto;
height: auto;
}
.item.slick-current {
border-bottom: 2px solid black;
}
.prev-arrow {
position: absolute;
left: 0;
top: 0;
z-index: 10;
}
.next-arrow {
position: absolute;
right: 0;
z-index: 10;
top: 0;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick-theme.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="carousel">
<div class="item">
tab number 1
</div>
<div class="item">
tab number 2
</div>
<div class="item">
tab number 3
</div>
<div class="item">
tab number 4
</div>
<div class="item">
tab number 5
</div>
<div class="item">
tab number 6
</div>
</div>
</div>
</div>
</div>
关于javascript - 如何根据光滑的轮播宽度有条件地添加下一个和上一个箭头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49019559/
光滑,如何将查询映射到继承表模型? IE, 我有表A,B,C A是“父”表,B&C是“子”表 我想知道的是我该如何使用平滑模型,以便A将成为抽象的B&C具体类型,而查询A中的一行将导致B或C对象 类似
如果数据库尚不存在,有没有办法轻松创建数据库? Database.forURL("jdbc:mysql://127.0.0.1/database", driver = "com.mysql.jdbc.
我是 Java slick 的新手,我对“相机”的翻译有一个小问题。我有这个代码: package chapterOne; import org.newdawn.slick.Animation; im
我正在尝试使用 Slick 渲染健康栏。我想要一个红色矩形,前面有一个绿色矩形来显示剩余的生命值。这是我到目前为止所拥有的: Rectangle healthBG = new Rect
有一个225px的方 block 。在里面插入一张大尺寸的图片(850 像素)。她走到外面。 看起来像这样: .content {display: inline-block;} .column {fl
我正在用 Java slick 编写游戏,我想添加消息管理。应该有一个 ArrayList,其中包含所有尚未发送的消息。每 2 秒应显示列表中的下一项。 我的逻辑: 在更新方法中,应显示第一条消息。
case class Account(var email:String, var pass:String, var familyId: Int, var accessId: Int, id: Opti
Content should wrap Content should wrap Content should wrap C
我正在使用 JQuery Slick Slider http://kenwheeler.github.io/slick/效果非常好。 我还运行了一个单独的脚本,用于检查页面 url,如果光滑 slid
我知道如何使用 click, scroll 的事件处理函数和其他默认事件。 目前我正在使用一个名为 slick slider 的 slider 插件。并且它工作正常,我想用定义的函数而不是匿名函数替换
我有 slider ,每个 slider 都包含视频作为背景和播放/暂停按钮。尝试通过单击正确的按钮来播放视频,但出现以下行为:我单击第二张幻灯片中的播放按钮,视频从第一张幻灯片中播放。暂停按钮也是如
我正在尝试在我的页面上实现一个光滑的 slider 。在浏览精美的文档时,他们提到要以响应方式使用 slider ,请遵循代码(我在下面发布)。我无法理解断点的用途。谁能给我解释一下代码。我尝试谷歌搜
我遇到了光滑 slider 的问题,我想创建一个应该在光滑 slider 上打开的灯箱,我想在灯箱中添加一些内容,主要问题是我不知道如何我可以将内容添加到灯箱部分吗? $('.works-slides
我正在尝试使用一个 slider ,它附带一个搜索框。此搜索框搜索 slider 中的用户名称。 目前,当用户开始在输入框中键入内容时,搜索框会自动完成全名。 例如,他们输入“Joh”,建议输入“Jo
我一直在尝试创建类似 this 的东西使用 slick.js,我真的无法理解它。 我已经准备好了当前的代码。如何使中心幻灯片图像的宽度和高度为 100% 并为幻灯片添加填充?好像不行。 我真的很感激任
我使用光滑 slider 创建了 slider 。我遇到的问题是在线断点工作正常的宽度。 但是,当我以正常方式写入 html file 时,相同的代码不起作用。谁能帮我这个。从检查中检查并查看正常代码
我正在尝试在输入字段中删除可拖动选项(以便我可以选择文本并使用箭头在字段内导航)。 var slider = $('.slider').slick({ infinite: false,
当它到达 breakpoint 时,如 990px,我在 slick slider 中遇到了问题。它删除了背景并且没有显示任何类型的错误。 iconic 我正在使用这个 javascript 来提
我想将光滑 slider 的点定位在上一个和下一个按钮之间。Slick 提供设置让您定位点/按钮。但它们会互相显示。 这是我的代码: $('.slider').slick({ arrows:
我在网站上创建了一个光滑的 slider 。我可以看到它进入“光滑模式”,但也没有显示我告诉它的幻灯片数量。它们都在那里,我可以通过更改它们的“左”和“不透明度”CSS 值来显示它们。 我将无法复制这
我是一名优秀的程序员,十分优秀!