hidden.vue 2.0 KB

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