hidden.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div class="swap"
  3. :class="{
  4. hasPadding:heightSlot>400
  5. }"
  6. >
  7. <div
  8. class="eidt-box"
  9. :class="{
  10. show:isShow,
  11. hide:isHide
  12. }"
  13. :style="siteHeight"
  14. style="transition: all .2s;">
  15. <slot></slot>
  16. </div>
  17. <div :title="titleMsg" v-if="heightSlot>400" class="bar" @click="showall">
  18. <svg width="20" viewBox="0,0 20,10">
  19. <path v-if="isShow" d="M 0,5
  20. L10,10
  21. L 20,5" fill="#fff" stroke="#999">
  22. </path>
  23. <path v-if="!isShow" d="M 0,5
  24. L10,0
  25. L 20,5" fill="#fff" stroke="#999">
  26. </path>
  27. </svg>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. export default {
  33. data(){
  34. return{
  35. siteHeight:{
  36. height:''
  37. },
  38. isShow:true,
  39. isHide:false,
  40. // 盒子高度
  41. heightSlot:0,
  42. titleMsg:'点击展开'
  43. }
  44. },
  45. methods:{
  46. showall(){
  47. this.isShow = !this.isShow;
  48. this.isHide = !this.isHide;
  49. if(this.isHide){
  50. this.siteHeight = {height:this.heightSlot+ 'px'};
  51. this.titleMsg = '点击收起'
  52. }else{
  53. this.siteHeight = {
  54. height:'400px'
  55. }
  56. this.titleMsg = '点击展开'
  57. }
  58. }
  59. },
  60. mounted(){
  61. this.heightSlot = this.$slots.default[0].elm.offsetHeight;
  62. if(this.heightSlot<400){
  63. this.siteHeight = {height:''};
  64. }else{
  65. this.siteHeight = {height:'300px'};
  66. }
  67. }
  68. }
  69. </script>
  70. <style lang="scss" scoped>
  71. .swap{
  72. position: relative;
  73. background: #F2F4F5;
  74. margin: 16px 0;
  75. }
  76. .hasPadding{
  77. padding-bottom:30px;
  78. }
  79. .show{
  80. overflow:hidden;
  81. position: relative;
  82. }
  83. .hide{
  84. position: relative;
  85. }
  86. .bar{
  87. height: 30px;
  88. width: 100%;
  89. bottom: 0;
  90. background: linear-gradient(rgba(255, 255, 255, 0),#fafafa);
  91. position: absolute;
  92. z-index: 999 ;
  93. text-align: center;
  94. cursor: pointer;
  95. svg{
  96. vertical-align: bottom;
  97. }
  98. }
  99. </style>