jquery bxslider 插件中的自定义分页器

发布于 2024-11-30 13:05:51 字数 1521 浏览 0 评论 0原文

我在使用 jQuery 时遇到了问题,但我真的不知道从哪里开始。

基本上我使用 bxslider 插件 来制作轮播。

这是简化的 HTML:

<ul id="promos">
    <li>
        <h2>Event Title 1</h2>
    </li>
    <li>
        <h2>Event Title 2</h2>
    </li>
</ul>

和 jquery :

$('ul#promos').after('<div id="pager1"></div>');
$('ul#promos').bxSlider({
    displaySlideQty: 1,
    moveSlideQty: 1,
    infiniteLoop: false,
    controls: false, 
    pager: true,
    pagerSelector: '#pager1',
    auto: true,
    pause: 5000,
    speed: 1000
});

这将输出呈现为:

<ul id="promos">
    <li>
        <h2>Event Title 1</h2>
    </li>
    <li>
        <h2>Event Title 2</h2>
    </li>
</ul>
<div id="pager1">
    <a href="" class="pager-link pager-1 pager-active">1</a>
    <a href="" class="pager-link pager-2">2</a>
</div>

但是,我希望分页器使用相对的 h2 标题,而不是升序数字。理想情况下,它看起来像:

<div id="pager1">
    <a href="" class="pager-link pager-1 pager-active">Event Title 1</a>
    <a href="" class="pager-link pager-2">Event Title 2</a>
</div>

注意:此轮播中最多可以有六个事件。

这是一个例子: http://jsfiddle.net/adrianjacob/gHpBT/3/

任何从何处开始的指针都会非常感谢。

I'm having an issue with jQuery and I don't really know where to start.

Basically I am using the bxslider plugin to make a carousel.

Here is simplified HTML:

<ul id="promos">
    <li>
        <h2>Event Title 1</h2>
    </li>
    <li>
        <h2>Event Title 2</h2>
    </li>
</ul>

And the jquery :

$('ul#promos').after('<div id="pager1"></div>');
$('ul#promos').bxSlider({
    displaySlideQty: 1,
    moveSlideQty: 1,
    infiniteLoop: false,
    controls: false, 
    pager: true,
    pagerSelector: '#pager1',
    auto: true,
    pause: 5000,
    speed: 1000
});

This renders the output as:

<ul id="promos">
    <li>
        <h2>Event Title 1</h2>
    </li>
    <li>
        <h2>Event Title 2</h2>
    </li>
</ul>
<div id="pager1">
    <a href="" class="pager-link pager-1 pager-active">1</a>
    <a href="" class="pager-link pager-2">2</a>
</div>

However, I want the pager to use the relative h2 titles, rather then ascending numbers. So ideally it would look like:

<div id="pager1">
    <a href="" class="pager-link pager-1 pager-active">Event Title 1</a>
    <a href="" class="pager-link pager-2">Event Title 2</a>
</div>

Note: there can be up to six events in this carousel.

Here is an example:
http://jsfiddle.net/adrianjacob/gHpBT/3/

Any pointers where to start would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猫九 2024-12-07 13:05:51

我刚刚使用 bxSlider 回调和公共方法构建了自己的寻呼机。

我正在使用 haml 和 Coffeescript,但你应该明白了。

我在自定义分页器链接上使用 data-id 属性将该链接绑定到特定幻灯片

HAML

%ul.landing-links
  %li <a href="#" data-id="0" class="active">Slide One</a>
  %li <a href="#" data-id="1">Slide Two</a>

CoffeeScript

landing_slides = $("#landing-slides").bxSlider
  controls: false,
  auto: true,
  pause: 10000,
  autoHover: true,
  onAfterSlide: (num, qty, obj) ->
    # Switch the active class to the corresponding pager link
    $("ul.landing-links li a.active").removeClass("active")
    $("ul.landing-links li a[data-id=#{num}]").addClass("active")

$('ul.landing-links li a').click (e) ->
  e.preventDefault()
  landing_slides.goToSlide($(this).data('id')) # Get the data-id attribute value
  landing_slides.startShow() # This is needed to restart the auto scroll

I just built my own pager using the bxSlider callbacks and public methods.

I'm using haml and coffeescript, but you should get the idea.

I'm using a data-id attribute on the custom pager links to tie that link to a particular slide

HAML

%ul.landing-links
  %li <a href="#" data-id="0" class="active">Slide One</a>
  %li <a href="#" data-id="1">Slide Two</a>

CoffeeScript

landing_slides = $("#landing-slides").bxSlider
  controls: false,
  auto: true,
  pause: 10000,
  autoHover: true,
  onAfterSlide: (num, qty, obj) ->
    # Switch the active class to the corresponding pager link
    $("ul.landing-links li a.active").removeClass("active")
    $("ul.landing-links li a[data-id=#{num}]").addClass("active")

$('ul.landing-links li a').click (e) ->
  e.preventDefault()
  landing_slides.goToSlide($(this).data('id')) # Get the data-id attribute value
  landing_slides.startShow() # This is needed to restart the auto scroll
请叫√我孤独 2024-12-07 13:05:51

我使用 http://bxslider.com/examples/thumbnail-pager-2 上的示例解决了这个问题

该示例使用“buildPager:”用图像替换标准的 1,2,3,4 寻呼机,示例:

$(function(){
  $('#slider1').bxSlider({
    pager: true,
    buildPager: function(slideIndex){
      switch (slideIndex){
        case 0:
          return '<a href=""><img src="/sites/all/themes/bx/images/pic_velvet1_thumb.jpg" /></a>';
        case 1:
          return '<a href=""><img src="/sites/all/themes/bx/images/pic_velvet2_thumb.jpg" /></a>';
        case 2:
          return '<a href=""><img src="/sites/all/themes/bx/images/pic_velvet3_thumb.jpg" /></a>';
        case 3:
          return '<a href=""><img src="/sites/all/themes/bx/images/pic_velvet4_thumb.jpg" /></a>';
      }
    }
  });
});

I figured this out using an example on http://bxslider.com/examples/thumbnail-pager-2

The example uses "buildPager:" replaces the standard 1,2,3,4 pager with images, the example:

$(function(){
  $('#slider1').bxSlider({
    pager: true,
    buildPager: function(slideIndex){
      switch (slideIndex){
        case 0:
          return '<a href=""><img src="/sites/all/themes/bx/images/pic_velvet1_thumb.jpg" /></a>';
        case 1:
          return '<a href=""><img src="/sites/all/themes/bx/images/pic_velvet2_thumb.jpg" /></a>';
        case 2:
          return '<a href=""><img src="/sites/all/themes/bx/images/pic_velvet3_thumb.jpg" /></a>';
        case 3:
          return '<a href=""><img src="/sites/all/themes/bx/images/pic_velvet4_thumb.jpg" /></a>';
      }
    }
  });
});
三岁铭 2024-12-07 13:05:51

请查看下面的 html 代码进行分页

jQuery(document).ready(function(){        
  jQuery('#bxslider1').bxSlider({
    pagerCustom: '#bxsliderlist1'
  });   
});
<ul id="bxslider1">
  <li>
    your contant
  </li>
  <li>
    your contant
  </li>
  <li>
    your contant
  </li>
  <li>
    your contant
  </li>
</ul>
<ul id="bxsliderlist1">
  <li>
    <a data-slide-index="0">your contant</a>
  </li>
   <li>
    <a data-slide-index="1">your contant</a>
  </li>
   <li>
    <a data-slide-index="2">your contant</a>
  </li>
   <li>
    <a data-slide-index="3">your contant</a>
  </li>
  
</ul>

Please check out the below html code for pagination

jQuery(document).ready(function(){        
  jQuery('#bxslider1').bxSlider({
    pagerCustom: '#bxsliderlist1'
  });   
});
<ul id="bxslider1">
  <li>
    your contant
  </li>
  <li>
    your contant
  </li>
  <li>
    your contant
  </li>
  <li>
    your contant
  </li>
</ul>
<ul id="bxsliderlist1">
  <li>
    <a data-slide-index="0">your contant</a>
  </li>
   <li>
    <a data-slide-index="1">your contant</a>
  </li>
   <li>
    <a data-slide-index="2">your contant</a>
  </li>
   <li>
    <a data-slide-index="3">your contant</a>
  </li>
  
</ul>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文