ns-switch.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <view>
  3. <view class="weui-switch" :class="{ 'weui-switch-on': checked, 'color-base-border': checked }" @click="change()">
  4. <view class="bgview" :class="{ 'color-base-bg': checked }"></view>
  5. <view class="spotview"></view>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. name: 'nsSwitch',
  12. props: {
  13. checked: {
  14. type: Boolean,
  15. default: false
  16. }
  17. },
  18. methods: {
  19. change() {
  20. this.$emit('change');
  21. }
  22. }
  23. };
  24. </script>
  25. <style>
  26. .weui-switch {
  27. display: block;
  28. position: relative;
  29. width: 94rpx;
  30. height: 45rpx;
  31. outline: 0;
  32. border-radius: 30rpx;
  33. border: 1px solid;
  34. border-color: #dfdfdf;
  35. transition: background-color 0.1s, border 0.1s;
  36. }
  37. .weui-switch .bgview {
  38. content: ' ';
  39. position: absolute;
  40. top: 0;
  41. left: 0;
  42. width: 94rpx;
  43. height: 45rpx;
  44. border-radius: 30rpx;
  45. transition: transform 0.35s cubic-bezier(0.45, 1, 0.4, 1);
  46. }
  47. .weui-switch .spotview {
  48. content: ' ';
  49. position: absolute;
  50. top: 2rpx;
  51. left: 4rpx;
  52. width: 40rpx;
  53. height: 40rpx;
  54. border-radius: 50%;
  55. background-color: #ffffff;
  56. box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  57. transition: transform 0.35s cubic-bezier(0.4, 0.4, 0.25, 1.35);
  58. }
  59. .weui-switch-on {
  60. border-color: #6f6f6f;
  61. }
  62. .weui-switch-on .bgview {
  63. border-color: #1aad19;
  64. }
  65. .weui-switch-on .spotview {
  66. transform: translateX(48rpx);
  67. }
  68. </style>