Foundation 6 Orbit: Change Slide programatically

隐身守侯 提交于 2020-01-07 02:14:21

问题


On Foundation 6.

I have an orbit slider that, besides the default behaviour, it also needs to be able to change the slide when an outside button is clicked.

Is there a way to make this work?

I've tried this code:

jQuery('#theslider').foundation('changeSlide', true, slide_id); 

//slide_id is the jQuery object's slide ex: jQuery(#slideid);

It kind of works, but it works erratically.

It sometimes works fine for a while, but a some point then the slide goes fast and disappears from the screen, or simply freezes.

I can't seem to find a pattern on what's going on.

I'm not an expert on javascript so I might be missing something really obvious.


回答1:


My solution as follow:

$('.orbit-external-control').on('click', function () {
  var activeIdx = ~~$('.orbit .orbit-bullets .is-active').data('slide')
  var changeIdx = ~~$(this).data('slide')
  var isLTR = (changeIdx > activeIdx) ? true : false

  if (activeIdx ===  changeIdx)
    return

  var chosenSlide = $('.orbit .orbit-slide').filter(function (index) {
    return index === changeIdx
  })

  $('.orbit').foundation('changeSlide', isLTR, chosenSlide, changeIdx) 
})


来源:https://stackoverflow.com/questions/38534315/foundation-6-orbit-change-slide-programatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!