【问题标题】:Swiper JS Auto Play stopped after move to other tab panel in laravel + bootstrap在 laravel + bootstrap 中移动到其他选项卡面板后,Swiper JS Auto Play 停止
【发布时间】:2018-05-02 16:40:49
【问题描述】:

我是 laravel 的新手,使用 swiper 库 (http://idangero.us/) 作为滑块。

我的幻灯片运行良好,但问题是移动到另一个选项卡后自动播放停止了。我已经尝试过 update、startAutoPlay 和 init 方法,但不起作用。我需要在顶部创建带有选项卡菜单的滑块,当单击选项卡菜单时,将显示选项卡菜单类别中的图像。这是我的代码:

图库.blade.php

@extends('layouts.template')

@section('title', trans('labels.home'))

@section('other-style')
    <link href="{{asset('css/global.css')}}" rel="stylesheet">
    <link href="{{asset('css/gallery.css')}}" rel="stylesheet">
    <link href="{{asset('css/swiper.min.css')}}" rel="stylesheet">

@endsection

@section('main')
    <section id="floor-content">
        <div class="container">
            <h1 class="text-center mh-title-h1">@lang('labels.galery')</h1>
            <section id="gallery-section">
                <!-- Nav tabs -->
                <ul class="nav nav-pills nav-justified mh-nav-pills" role="tablist">
                    <li role="presentation" class="active"><a href="#display" aria-controls="home" role="tab" data-toggle="pill">@lang('labels.display')</a></li>
                    <li role="presentation"><a href="#visit" aria-controls="visit" role="tab" data-toggle="pill">@lang('labels.visit')</a></li>
                    <li role="presentation"><a href="#others" aria-controls="others" role="tab" data-toggle="pill">@lang('labels.others')</a></li>
                </ul>

                <!-- Tab panes -->
                <div class="tab-content" style="margin-top: 200px;">
                    <div role="tabpanel" class="tab-pane active" id="display">
                        <div class="swiper-container">
                            <div class="swiper-wrapper">
                                <div class="swiper-slide" style="background-image: url('{{asset('images/galleries/beateau_musee_marine580.jpg')}}'); height: 300px; width: auto;"></div>
                                <div class="swiper-slide" style="background-image: url('{{asset('images/galleries/Echard_Houssay_ill_01-900w.jpg')}}'); height: 300px; width: auto;">></div>
                                <div class="swiper-slide" style="background-image: url('{{asset('images/galleries/full_Musee-national-de-la-Marine-4.jpg')}}'); height: 300px; width: auto;">></div>
                            </div>
                            <!-- Add Pagination -->
                            <div class="swiper-pagination"></div>
                        </div>
                    </div>
                    <div role="tabpanel" class="tab-pane" id="visit">
                        <div class="swiper-container">
                            <div class="swiper-wrapper">
                                <div class="swiper-slide" style="background-image: url('{{asset('images/galleries/34226012370_d815695c43_c.jpg')}}'); height: 300px; width: auto;"></div>
                                <div class="swiper-slide" style="background-image: url('{{asset('images/galleries/Maritime_ControlPanel-min.jpg')}}'); height: 300px; width: auto;"></div>
                                <div class="swiper-slide" style="background-image: url('{{asset('images/galleries/MM 4.jpg')}}'); height: 300px; width: auto;"></div>
                            </div>
                            <!-- Add Pagination -->
                            <div class="swiper-pagination"></div>
                        </div>
                    </div>
                    <div role="tabpanel" class="tab-pane" id="others">
                        <div class="swiper-container">
                            <div class="swiper-wrapper">
                                <div class="swiper-slide" style="background-image: url('{{asset('images/galleries/other_image_slider1.jpg')}}'); height: 300px; width: auto;"></div>
                                <div class="swiper-slide" style="background-image: url('{{asset('images/galleries/other_image_slider2.jpg')}}'); height: 300px; width: auto;"></div>
                                <div class="swiper-slide" style="background-image: url('{{asset('images/galleries/other_image_slider3.jpeg')}}'); height: 300px; width: auto;"></div>
                            </div>
                            <!-- Add Pagination -->
                            <div class="swiper-pagination"></div>
                        </div>
                    </div>
                </div>
            </section>
            <a href="{{url('display')}}" class="btn mh-btn btn-lg center-block" style="width: 400px; margin-top: 20px;">@lang('labels.continue') @lang('labels.exploring') <span class="glyphicon glyphicon-arrow-right"></span> @lang('labels.display') @lang('labels.item')</a>
        </div>
    </section>
@endsection

@section('other-script')
    <script src="{{asset('js/swiper.min.js')}}"></script>
    <script>
        $(document).ready(function () {
            var swiper = new Swiper('.swiper-container', {
                effect: 'cube',
                speed: 700,
                autoplay: 3000,
                loop: true,
                grabCursor: true,
                autoplayDisableOnInteraction: false,
                cubeEffect: {
                    shadow: true,
                    slideShadows: true,
                    shadowOffset: 20,
                    shadowScale: 0.94,
                },
                observer: true,
                observeParents: true,
                pagination: {
                    el: '.swiper-pagination',
                },
            });

            console.log(swiper);

            $("li[role='presentation']").children("a").click(function () {
                var swiper = $('.swiper-container');
                $.each(swiper, function( index, value ) {
                    value.swiper.update();
                });
            });
        });

    </script>
@endsection

【问题讨论】:

    标签: javascript jquery html twitter-bootstrap laravel-5


    【解决方案1】:

    已解决,我需要停止并重新开始自动播放:

    $("li[role='presentation']").children("a").click(function () {
                    var gallerySwiper = $('.swiper-container');
                    $.each(gallerySwiper, function( index, value ) {
                        value.swiper.stopAutoplay();
                        value.swiper.startAutoplay();
                    });
                });
    

    【讨论】:

      猜你喜欢
      • 2017-12-25
      • 1970-01-01
      • 2018-07-25
      • 1970-01-01
      • 1970-01-01
      • 2014-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多