账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    swiper里面插入的video无法拖动
    39
    0

    使用 vue-awesome-swiper (v3.1.3) 做了一个轮播图片,需要实现的功能,遇到了如下问题:
    1、滑动视频和图片都可以切换(如果只是图片没问题,但是视频在暂停状态下却无法滑动?)
    2、轮播图正方形,但是视频是长方形,默认视频一直顶部对其,怎么让视频垂直居中对其呢?

    swiper组件(基于vue-awesome-swiper (v3.1.3) 封装):

    <template>
        <div class="wrapper">
            <swiper ref="mySwiper" :options="swiperOption" v-if="list.length > 0">
                <swiper-slide v-for="(item, idx) in list" :key="idx">
                    <img v-if="item.mediaType == 'img'" class="swiper-img" :src="item.src" alt="">
                    <video ref="myvideo" name='myvideo' v-if="item.mediaType == 'video'" :src="item.src" controls="controls" :poster="item.poster"></video>
                </swiper-slide>
                <div class="swiper-pagination" slot="pagination"></div>
            </swiper>
        </div>
    </template>
    
    <script>
    
    export default {
        name: 'DetailSwiper',
        props:{
            list: Array
        },
        watch: {
            currentIdx (newval, oldval) {
                let videoList = $('.wrapper video').toArray()
                if(videoList.length > 0){
                    if(videoList.some(item => !item.paused) && videoList.some(item => !item.ended)){
                        videoList.forEach(element => {
                            element.pause()
                            element.currentTime=0
                        });
                    }
                }
            }
        },
        data(){
            let self = this;
            return {
                currentIdx: 0,
                swiperOption: {
                    //页码
                    pagination: '.swiper-pagination',
                    // autoplay: 3000,
                    loop: true,
                    paginationClickable: true,
                    on:{
                        transitionEnd: function() {
                            self.currentIdx = this.realIndex
                            // console.log(self.currentIdx)
                        }
                    },  
                },
            }
        },
    }
    </script>
    
    <style lang="stylus" scoped>
    .wrapper >>> .swiper-pagination-bullet-active
        background: #fff
    .wrapper
        overflow: hidden
        width: 100%
        height: 0
        padding-bottom: 100% 
        background: #eee
        .swiper-img
            width: 100%
    </style>
    
    
    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • 宁夜空 超级管理员 1楼

      Swiper 1.x版本中,视频插入后无法拖动可能是因为在 Swiper 1.x 中,提供了滑动和旋转功能,但是在 Swiper 2.x 中,这些功能已经被移除。

      如果你仍然需要在 Swiper 2.x 中使用滑动和旋转功能,你可以尝试以下方法:

      1. 将视频插入到 Swiper 2.x 中的 swiper-container 中,而不是 swiper-item

      javascript var mySwiper = new Swiper('.swiper-container', { slides: [ { active: false, id: 'video1' }, { active: false, id: 'video2' }, // ... ] });

      1. 使用 transform 属性来旋转视频。

      javascript var mySwiper = new Swiper('.swiper-container', { slides: [ { active: false, id: 'video1' }, { active: false, id: 'video2' }, // ... ], rotateAfterEachSlide: 3000 // 每次轮播3秒后旋转 });

      1. 如果你仍然需要在 Swiper 1.x 中使用滑动和旋转功能,你可以使用以下代码将 Swiper 1.x 的滑动和旋转功能移除:

      ```javascript var mySwiper = new Swiper('.swiper-container', { slides: [ { active: false, id: 'video1' }, { active: false, id: 'video2' }, // ... ] });

      mySwiper.on('transitionEnd', function(e) { mySwiper.unlock(); });

      mySwiper.on('切换', function(e) { mySwiper.lock(); }); ```

      请注意,这些方法可能会导致视频的播放速度减慢。在实际使用中,你可能需要根据你的需求进行调整。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部