首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Vue转换不起作用

Vue转换不起作用
EN

Stack Overflow用户
提问于 2018-04-21 00:45:29
回答 1查看 92关注 0票数 0

我想知道我在这里做错了什么,我的过渡不起作用了。我试图使切换到右或左的点击,它是工作的,但没有转换。我想我在这里错过了什么。

代码语言:javascript
复制
<template>
<div class="switchery" @click="activate" >
      <div class="switchery-check" v-bind:class="{active:isactive}"></div>
</div>
</template>

    <script>
      export default {
        data:function(){
          return{
            isactive:false
          }
        },
        methods:{
          activate:function (event) {
                 this.checked  = !this.checked;
                 this.isactive = this.checked;
          }
        }
      };

    </script>

    <style scoped>

    .switchery{
      width: 40px;
      height: 20px;
      border-radius: 20px;
      background-color: #09c;
      cursor: pointer;
      position: relative;
    }

    .switchery-check{
      transition: all 5s !important;
      position: absolute;
      left: 0;
      top: 0;
      height: 100%;
      width: 20px;
      background-color: #fff;
      border-radius: 100%;
    }

    .active.switchery-check {
      right: 0 !important;
      left: auto !important;
    }
    </style>
EN

回答 1

Stack Overflow用户

发布于 2018-04-21 01:40:38

问题是rightleft并没有触发动画,但是您的转换配置很好,看看background: red;是如何完美地转换的:

代码语言:javascript
复制
new Vue({
  el: '#app',
  data: function() {
    return {
      isactive: false
    }
  },
  methods: {
    activate: function(event) {
      this.checked = !this.checked;
      this.isactive = this.checked;
    }
  }
})
代码语言:javascript
复制
.switchery {
  width: 40px;
  height: 20px;
  border-radius: 20px;
  background-color: #09c;
  cursor: pointer;
  position: relative;
}

.switchery-check {
  transition: all 5s !important;
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 20px;
  background-color: #fff;
  border-radius: 100%;
}

.active.switchery-check {
  background: red; /* added for demo */
  right: 0 !important;
  left: auto !important;
}
代码语言:javascript
复制
<script src="https://unpkg.com/vue"></script>

<div id="app">
  <div class="switchery" @click="activate">
    <div class="switchery-check" v-bind:class="{active:isactive}"></div>
  </div>
</div>

对于您的情况,一种选择是transform: translate(100%);,而不是rightleft

代码语言:javascript
复制
new Vue({
  el: '#app',
  data: function() {
    return {
      isactive: false
    }
  },
  methods: {
    activate: function(event) {
      this.checked = !this.checked;
      this.isactive = this.checked;
    }
  }
})
代码语言:javascript
复制
.switchery {
  width: 40px;
  height: 20px;
  border-radius: 20px;
  background-color: #09c;
  cursor: pointer;
  position: relative;
}

.switchery-check {
  transition: all 5s !important;
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 20px;
  background-color: #fff;
  border-radius: 100%;
}

.active.switchery-check {
  background: red; /* added for demo */
  transform: translate(100%);
}
代码语言:javascript
复制
<script src="https://unpkg.com/vue"></script>

<div id="app">
  <div class="switchery" @click="activate">
    <div class="switchery-check" v-bind:class="{active:isactive}"></div>
  </div>
</div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49951317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档