Foundation 6 Orbit:以编程方式更改幻灯片 [英] Foundation 6 Orbit: Change Slide programatically

查看:132
本文介绍了Foundation 6 Orbit:以编程方式更改幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Foundation 6上.

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?

我尝试了以下代码:

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.

我不是javascript方面的专家,因此我可能会错过一些非常明显的东西.

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

推荐答案

我的解决方案如下:

$('.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) 
})

这篇关于Foundation 6 Orbit:以编程方式更改幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆