ati*_*tif 7 jquery carousel css-transitions twitter-bootstrap twitter-bootstrap-3
我在单页上有三个旋转木马滑块,我希望它们同时移动其中两个.我们都应该同时更改滑块图像.两者都有相同数量的图像/幻灯片.这是我正在使用的代码:
jQuery('#carousel-example-generic1, #carousel-example-generic2').carousel({
interval: 4000
});
Run Code Online (Sandbox Code Playgroud)
我也试过以下代码:
jQuery('.carousel').carousel({
pause:'false'
});
jQuery('#carousel-example-generic1').on('slide', function(){
jQuery('#carousel-example-generic2').carousel('next');
});
Run Code Online (Sandbox Code Playgroud)
但左右滑块在更换幻灯片时几乎没有延迟.这种延迟继续增加.这类问题有哪些已知问题?链接到该网站是这样的.
JSFiddle:链接
zes*_*ssx 12
为避免此延迟,您可以同时手动启动两个轮播,并使用自定义的事件处理方法.
$('.carousel-sync').carousel('cycle');
$('.carousel-sync').on('click', '.carousel-control[data-slide]', function (ev) {
ev.preventDefault();
$('.carousel-sync').carousel($(this).data('slide'));
});
$('.carousel-sync').on('mouseover', function(ev) {
ev.preventDefault();
$('.carousel-sync').carousel('pause');
});
$('.carousel-sync').on('mouseleave', function(ev) {
ev.preventDefault();
$('.carousel-sync').carousel('cycle');
});
Run Code Online (Sandbox Code Playgroud)
<div id="carousel-a" class="carousel slide carousel-sync">
...
</div>
<div id="carousel-b" class="carousel slide carousel-sync">
...
</div>
Run Code Online (Sandbox Code Playgroud)
$('.carousel-sync').on('slide.bs.carousel', function(ev) {
// get the direction, based on the event which occurs
var dir = ev.direction == 'right' ? 'prev' : 'next';
// get synchronized non-sliding carousels, and make'em sliding
$('.carousel-sync').not('.sliding').addClass('sliding').carousel(dir);
});
$('.carousel-sync').on('slid.bs.carousel', function(ev) {
// remove .sliding class, to allow the next move
$('.carousel-sync').removeClass('sliding');
});
Run Code Online (Sandbox Code Playgroud)
<div id="carousel-a" class="carousel slide carousel-sync" data-ride="carousel" data-pause="false">
...
</div>
<div id="carousel-b" class="carousel slide carousel-sync" data-ride="carousel" data-pause="false">
...
</div>
Run Code Online (Sandbox Code Playgroud)
请不要.sliding上课是必要的,以避免无限循环.