hidden.vue 2.4 KB

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