1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

element ui carousel swipe

Posted at

スライドショーってさ、スワイプでやりたいがね。
だからスワイプにできるようにと、ついでにレスポンシブ化しとくがね。

あー。んでもって一枚目だけ早めに読み込んでちょ。
2,3枚目だけ lazyload でええぇがね。

必要なライブラリ

・vue2-touch-events
・element ui
・VueLazyload

まずはこれで img タグを レスポンシブにしとく。


<style>

    img.responsive {
        width: 100%;
        height: 300px;
        object-fit: cover;
    }

</style>


template.vue

<div v-touch:swipe="swipeHandler">
    <el-carousel ref="photoFrame" :autoplay="false">
        <el-carousel-item v-for="(v,key) in data.photos" :key="key">
            <img v-if="key == 0" class="responsive" :src="'/gcp_storage/photo_300x300_' + v.id + '.jpg'">
            <img v-else class="responsive" v-lazy="'/gcp_storage/photo_300x300_' + v.id + '.jpg'">
        </el-carousel-item>
    </el-carousel>
</div>


.js

<script>
    methods: {

        swipeHandler (direction) {

            if(direction == 'left'){
                this.$refs.photoFrame.next();
            }

            if(direction == 'right'){
                this.$refs.photoFrame.prev();
            }

        },
        
</script>


ソースはコピペじゃ動かんけど、さっしてちょ

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?