Swiper JS Phonegap问题

时间:2017-01-06 11:55:57

标签: javascript cordova swiper

我正在使用Swiper JS为我的图片库工作的webapp。没有使用Phonegap它可以正常工作,但使用Phonegap" slide"效果doenst正常工作和JS的上一个/下一个按钮显示,但它们是不可触摸的。奇怪的是,它在更改浏览器窗口(firefox)的大小后开始工作。有什么想法吗?

        <!-- Swiper -->
    <div class="swiper-container">
        <div id="swiper-wrapper" class="swiper-wrapper">
            <div id="img0" class="swiper-slide"></div>
            <div id="img1" class="swiper-slide"></div>
            <div id="img2" class="swiper-slide"></div>
            <div id="img3" class="swiper-slide"></div>
            <div id="img4" class="swiper-slide"></div>
            <div id="img5" class="swiper-slide"></div>
            <div id="img6" class="swiper-slide"></div>
            <div id="img7" class="swiper-slide"></div>
            <div id="img8" class="swiper-slide"></div>
        </div>
        <!-- Add Arrows -->
        <div class="swiper-button-next swiper-button-white"></div>
        <div class="swiper-button-prev swiper-button-white"></div>
        <!-- Add Pagination -->
        <div class="swiper-pagination"></div>
    </div>

    <!-- Swiper JS -->
    <script src="js/swiper.min.js"></script>

    <!-- Initialize Swiper -->
    <script>
    var swiper = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        paginationClickable: true,
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',
        spaceBetween: 30
    });
    </script>

图像通过DOM加载

1 个答案:

答案 0 :(得分:0)

我用以下解决方案解决了这个问题:

循环浏览我的图片并将它们添加到swiper-wrapper中:

var str = "<div class=swiper-slide><a href=data:iamge/png;base64,"+image_data+" data-lightbox="+image_id+" data-title="+image_date+" "+image_time+"><img src=data:image/png;base64,"+image_data+" class=gallery_images></img></a></div>";
$('.swiper-wrapper').append(str);

然后引导Swiper:

    var swiper = new Swiper('.swiper-container', {
    pagination: '.swiper-pagination',
    paginationClickable: true,
    nextButton: '.swiper-button-next',
    prevButton: '.swiper-button-prev',
    spaceBetween: 30
});

并在设置divs属性后显示:inherit我必须更新swiper对象:

swiper.update(true);