style.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <view class="style-box" @click.stop="setPagesStyle()">
  3. <view :class="['style-status' , `${pageStyle}_style` ]"></view>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. pageStyle: 'daytime' , // daytime : '日渐模式' , black: 夜间模式
  11. };
  12. },
  13. methods:{
  14. setPagesStyle(){
  15. this.pageStyle = this.pageStyle === 'daytime' ? 'black' : 'daytime'
  16. }
  17. }
  18. }
  19. </script>
  20. <style lang="scss" scoped>
  21. .style-box{
  22. width: 72rpx;
  23. height: 44rpx;
  24. border-radius: 30rpx;
  25. background-color: #5C5F70;
  26. position: relative;
  27. .style-status{
  28. width: 39rpx;
  29. height: 39rpx;
  30. background-color: #fff;
  31. border-radius: 50%;
  32. position: absolute;
  33. background-size: 39rpx 39rpx;
  34. top: 50%;
  35. left: 5rpx;
  36. transform: translateY(-50%);
  37. // transition: left 3s linear;
  38. transition:left,background 0.5s;
  39. }
  40. .black_style{
  41. background: url("@/static/logo.png") no-repeat center center;
  42. left: 30rpx;
  43. // width:100rpx;
  44. }
  45. .daytime_style{
  46. background: url("@/static/logo.png") no-repeat center center;
  47. left: 5rpx;
  48. }
  49. }
  50. </style>