简体   繁体   English

引导选项卡在单击时刷新

[英]Bootstrap tab refresh on click

On this project there is Bootstrap tab and Camera image slider. 在此项目中,有Bootstrap选项卡和Camera image滑块。 There is two tabs named Video news/ Picture news. 有两个选项卡,分别名为视频新闻/图片新闻。 And both have their sub tabs. 两者都有其子选项卡。 And the subtabs use their own Camera slider. 子选项卡使用其自己的“相机”滑块。 So the problem with this is when i click on subtabs the image sliders are breaking. 因此,这是当我单击子选项卡时图像滑块损坏的问题。 What i need is to refresh the image slider or reload the slider so could they get their proper width. 我需要刷新图像滑块或重新加载滑块,以便它们能获得适当的宽度。

So is there any proper way to do this? 那么,有什么适当的方法可以做到这一点吗?

Tab.active -> Sub tab -> Slider /on first it's ok/
           -> Sub tab -> Slider /Click on sub tab it breaks/
           -> Sub tab -> Slider
Tab        -> Sub tab -> Slider /all breaks/
           -> Sub tab -> Slider /Click on sub tab it breaks/
           -> Sub tab -> Slider

You have to attach an event to Tabs and render the Camera slider when necessary. 您必须将事件附加到选项卡,并在必要时渲染“相机”滑块。

Basically, you insert something like this into your code 基本上,您可以在代码中插入类似的内容

$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  // refresh the slider
})

Remember to change a[data-toggle="tab"] to match your tab links. 请记住更改a[data-toggle="tab"]以匹配您的标签链接。

You have two events available: 您有两个可用的事件:

  • shown.bs.tab - This event fires on tab show, but before the new tab has been shown. shown.bs.tab此事件在标签显示时触发,但在显示新标签之前。 Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively. 使用event.targetevent.relatedTarget分别定位活动选项卡和上一个活动选项卡(如果有)。
  • shown.bs.tab - This event fires on tab show after a tab has been shown. shown.bs.tab显示标签后,此事件在标签显示上触发。 Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively. 使用event.targetevent.relatedTarget分别定位活动选项卡和上一个活动选项卡(如果有)。

As you can see, by accessing active tab ( e.releatedTarget ) you can simply get the ID of the container where slider you need to refresh lives. 如您所见,通过访问活动选项卡( e.releatedTarget ),您可以简单地获取需要刷新滑块的容器的ID。

Look at the "Events" section for more 查看“事件”部分以了解更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM