当前位置:   article > 正文

vue 侧边可拖动导航栏(展开及收缩)_侧边导航收起

侧边导航收起

效果:

1.点击收起按钮,导航栏收起,鼠标移动到导航栏cursor:move鼠标移动光标提示导航栏可移动,鼠标移动到img上cursor:pointer出现小手,提示可点击跳转

2.导航栏展开或收起可移动到任何位置展开收起,展开或收起的位置随移动的位置改变

代码部分:

  1. <template>
  2. <div id="index_tip_" :style="{padding:'20px 0',top:showIcon?boxTop:box2Top}">
  3. <div id="index_tip_in" v-show="showIcon">
  4. <div class="center center0" >
  5. <img @click="toItPageFn" src="../../../static/images/IT5000.png" alt="" />
  6. </div>
  7. <div class="center center1">
  8. <img @click="toCommontProblemFn" src="../../../static/images/IT6000.png" alt=""/>
  9. </div>
  10. <div class="center center2">
  11. <img @click="toOperationFn" src="../../../static/images/IT7000.png" alt="" />
  12. </div>
  13. <div class="center center3">
  14. <div @click="toOpenOrCloseFn(2)" class="iconfont iconpullup01">
  15. </div> 收起</div>
  16. </div>
  17. <div v-show="!showIcon" class="open-icon" >
  18. <img @click="showIcon=true" src="../../../static/images/IT4000.png" alt="" />
  19. <div class="iconfont iconpulldown01" @click="toOpenOrCloseFn(1)"></div>
  20. <div class="title">展开</div>
  21. </div>
  22. </div>
  23. </template>
  24. <script>
  25. export default{
  26. //main.js:Vue.prototype.$pageHeight = 1 * 100 + 'vh'
  27. data(){
  28. return{
  29. showIcon: true,
  30. boxTop:`calc(${this.$pageHeight} - 340px)`,
  31. box2Top:`calc(${this.$pageHeight} - 170px)`}
  32. }
  33. }
  34. mounted() { this.getmoveFn()}
  35. methods:{
  36. toOpenOrCloseFn(flag){
  37. this.showIcon=flag==1
  38. let box=document.getElementById("index_tip_");
  39. this.boxTop=box.offsetTop+"px"
  40. this.box2Top=box.offsetTop+"px"
  41. },
  42. getmoveFn(){
  43. let divX=0;
  44. let divY=0;
  45. let mouseX=0;
  46. let mouseY=0;
  47. let box=document.getElementById("index_tip_");
  48. //为box绑定一个鼠标按下事件
  49. if(box){
  50. box.onmousedown=function(e){
  51. console.log(e);
  52. //获取盒子距离浏览器可视窗口的水平距离和垂直距离
  53. divX=this.offsetLeft;
  54. divY=this.offsetTop;
  55. //获取鼠标距离浏览器可视窗口的水平位置和垂直位置
  56. mouseX=e.clientX;
  57. mouseY=e.clientY;
  58. //为全局绑定一个鼠标移动事件(1.为什么不给box绑定?)
  59. document.onmousemove=function(e){
  60. //获取移动后的水平偏移量和垂直偏移量
  61. let disX=e.clientX-mouseX;
  62. let disY=e.clientY-mouseY;
  63. //令箱子移动:移动前的位置+移动后的位置
  64. box.style.left=disX+divX+"px";
  65. box.style.top=disY+divY+"px";
  66. }
  67. //为盒子绑定一个鼠标移出事件,使箱子停止移动
  68. document.onmouseup=function(){
  69. document.onmousemove=null;
  70. document.onmouseup=null;
  71. }
  72. }
  73. }
  74. },
  75. toItPageFn(){},
  76. toCommontProblemFn() {},
  77. toOperationFn() {},
  78. }
  79. </script>
  80. <style lang='less'>
  81. #index_tip:hover {
  82. .open-icon {
  83. .iconfont{
  84. font-size: 33px !important;
  85. }
  86. img{
  87. width:81%;
  88. }
  89. }
  90. }
  91. #index_tip_{
  92. position: fixed;
  93. right: 16px;
  94. width:65px;
  95. z-index: 99999999;
  96. box-shadow: -1px 0px 7px #d3daeb;
  97. background-color: #ffffff;
  98. cursor: move;
  99. border-radius: 50px;
  100. #index_tip_in{
  101. img{
  102. margin: 10px 0;
  103. width: 80%;
  104. cursor: pointer;
  105. }
  106. img:hover {
  107. width: 83%;
  108. height: 32%;
  109. background-color: #eef4ff !important;
  110. }
  111. }
  112. .center3{
  113. font-size: 12px;
  114. color: rgb(51, 49, 49);
  115. font-weight: 550;
  116. margin-bottom: 9px;
  117. font-family:'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
  118. .iconpullup01{
  119. width: 50%;
  120. margin-left: 16px;
  121. font-size: 30px !important;
  122. color: #bacdff;
  123. }
  124. }
  125. .open-icon {
  126. text-align: center;
  127. .title {
  128. color: #000;
  129. margin-bottom:8px;
  130. margin-top: -2px;
  131. }
  132. .iconfont {
  133. font-size: 25px !important;
  134. color: #bacdff;
  135. }
  136. img{
  137. width:80%;
  138. }
  139. img:hover{
  140. width:81%;
  141. cursor: pointer;
  142. }
  143. }
  144. }
  145. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/971796
推荐阅读
相关标签
  

闽ICP备14008679号