gpt4 book ai didi

javascript - bx-slider 在图片外滑动字幕

转载 作者:行者123 更新时间:2023-11-28 01:16:43 26 4
gpt4 key购买 nike

我正在尝试弄清楚如何在 bx-slider 类之外滑动自定义字幕。我只找到与此类似的答案 here ,它使用图像属性,但我的问题是我希望能够在 div 内滑动标题和图像,与 bx-slider 分开,如果可能的话。

到目前为止我有这个:

HTML:

<!--image slider desktop-->
<div id="hero">
<ul class="bxslider">
<li>
<a href="www.google.com">
<img src="http://placehold.it/350x150" class="slider-img-responsive">
</a>
</li>
<li>
<a href="www.google.com">
<img src="http://placehold.it/350x150" class="slider-img-responsive">
</a>
</li>
</ul>
</div>
<!-- slider text-->
<div class="mobile-homepage-header">
<!-- TODO: slide text relative to image slider-->
<ul id="slider-text" style="list-style-type:none;padding:0;">
<li>
<h1>Lorem ipsum 1</h1>
<h2>Lorem ipsum dolor sit 1</h2>
<a href="www.google.com">Button 1</a>
</li>
<li>
<h1>Lorem ipsum 2.</h1>
<h2>Lorem ipsum dolor sit 2</h2>
<a href="www.google.com">Button 2</a>
</li>
</ul>
</div>

JQuery:

$('#hero .bxslider').bxSlider({
auto: true,
infiniteLoop: true,
pager: false,
controls: true,
pause: 5000,
onSliderLoad: function(currentIndex) {
$('#slider-text li').html($('.bxslider li').eq(currentIndex)); // select the current index of the slider
},
onSlideBefore: function($slideElement, oldIndex, newIndex) {
$('#slider-text li').html($slideElement); // slide text along with image
}
});

最佳答案

听起来您想要的这个字幕框与 slider 具有相同的功能。我制作了 2 个 bxSliders:

  • .bxslider修改如下:
    • var bx 引用
    • 已删除 onSliderLoad()回调
    • 已更改 onSlideBefore() 回调到新函数 syncTextSlider
  • #slider-text修改如下:
    • 实例化为 bxSlider
    • var cx 引用
    • 备注:controls: false
  • 定义了一个新函数 syncTextSlider
    • 之前.bxslider移动到新幻灯片,syncSliderText被称为。
    • 此函数然后使用 bxSlider API 方法 goToSlide() #slider-text
  • #slider-text的动向取决于.bxslider我删除的 Action #slider-text的控制。
  • 样式 .bxslider两个 slider 之间的控件,如果您更喜欢它们在原始位置,只需删除位于 <style> 中的样式即可<head> 内的 block .

<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>35486338</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/bxslider/4.2.5/jquery.bxslider.css">
<style>
/* Remove style to relocate controls to original position */
.bx-controls-direction a {
top: 125% !important;
}
</style>
</head>

<body>
<!--image slider desktop-->
<div id="hero">
<ul class="bxslider">
<li>
<a href="www.google.com">
<img src="http://placehold.it/350x150/000/0ff/?text=1" class="slider-img-responsive">
</a>
</li>
<li>
<a href="www.google.com">
<img src="http://placehold.it/350x150/000/fff/?text=2" class="slider-img-responsive">
</a>
</li>
<li>
<a href="www.google.com">
<img src="http://placehold.it/350x150/000/e00/?text=3" class="slider-img-responsive">
</a>
</li>
<li>
<a href="www.google.com">
<img src="http://placehold.it/350x150/000/f3f/?text=4" class="slider-img-responsive">
</a>
</li>
<li>
<a href="www.google.com">
<img src="http://placehold.it/350x150/000/3f3/?text=5" class="slider-img-responsive">
</a>
</li>
</ul>
</div>
<!-- slider text-->
<div class="mobile-homepage-header">
<ul id="slider-text">
<li>
<h1>Title 1</h1>
<h2>Byline 1</h2>
<a href="www.google.com">Button 1</a>
</li>
<li>
<h1>Title 2</h1>
<h2>Byline 2</h2>
<a href="www.google.com">Button 2</a>
</li>
<li>
<h1>Title 3</h1>
<h2>Byline 3</h2>
<a href="www.google.com">Button 3</a>
</li>
<li>
<h1>Title 4</h1>
<h2>Byline 4</h2>
<a href="www.google.com">Button 4</a>
</li>
<li>
<h1>Title 5</h1>
<h2>Byline 5</h2>
<a href="www.google.com">Button 5</a>
</li>
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/bxslider/4.2.5/jquery.bxslider.min.js"></script>
<script>
var bx = $('.bxslider').bxSlider({
auto: true,
infiniteLoop: true,
pager: false,
controls: true,
pause: 5000,
onSlideBefore: syncTextSlider
});

var cx = $("#slider-text").bxSlider({
infiniteLoop: true,
pager: false,
controls: false
});

function syncTextSlider($ele, from, to) {
cx.goToSlide(to);
}
</script>
</body>

</html>

关于javascript - bx-slider 在图片外滑动字幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35486338/

26 4 0
文章推荐: javascript - 打开菜单时 mask /覆盖页面
文章推荐: javascript - 多复选框值检查和结果更新表数据
文章推荐: html - Thymeleaf:附加到 html 元素/避免重复迭代
文章推荐: javascript - 在容器滚动时将隐藏的