我试图弄清楚如何在bx-slider类之外滑动自定义标题。我只找到类似于here的答案,它使用了图像属性,但我的问题是我希望能够将图片与div中的图像一起滑动,与bx滑块分开,如果这样&# 39;可能。
到目前为止,我有这个:
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
}
});
答案 0 :(得分:1)
听起来你想要的这个字幕框与滑块具有相同的功能。我做了2个bxSliders:
.bxslider
修改如下:
var bx
onSliderLoad()
回拨onSlideBefore()
回调更改为新功能syncTextSlider
#slider-text
修改如下:
var cx
controls: false
syncTextSlider
.bxslider
移至新幻灯片之前,系统会调用syncSliderText
。#slider-text
goToSlide()
#slider-text
的移动取决于.bxslider
的移动,我删除了#slider-text
的控件。.bxslider
控件,如果您希望它们位于原始位置,只需删除位于<style>
内的<head>
块中的样式。
<!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>