use.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <div class="container">
  3. <div class="common-title">
  4. {{$t('service.use')}}
  5. </div>
  6. <div class="use-layout " :class="language">
  7. <template v-if="isFireFox" >
  8. <div class="ls-outer">
  9. <lselect :options="navs" :selected="navActive" class="select firefox-select" :class="{oy: navs.length > 15}" @change="handleChange" />
  10. <div class="ls-scrollbar">
  11. <div ref="thumb" class="ls-scroll-thumb" :style="{top:scorlltop}"></div>
  12. </div>
  13. </div>
  14. <scrollbar :scorlltop='scorlltop'>
  15. <div slot="con" class="use-con" ref="dcon" id="dcon">
  16. <img class="img" v-for="(item,i) in current.size" :src="`${$cdn}images/use/${current.id}/${language==='en'?'en':'zh'}/${i+1}.jpg`" :key="i" :alt="i+1">
  17. </div>
  18. </scrollbar>
  19. </template>
  20. <template v-else>
  21. <lselect :options="navs" :selected="navActive" class="select" :class="{oy: navs.length > 15}" @change="handleChange" />
  22. <div class="use-con" style="position:static" ref="dcon" id="dcon">
  23. <img class="img" v-for="(item,i) in current.size" :src="`${$cdn}images/use/${current.id}/${language==='en'?'en':'zh'}/${i+1}.jpg`" :key="i" :alt="i+1">
  24. </div>
  25. </template>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import lselect from '@/components/lselect'
  31. import scrollbar from '../plugin/ff-scrollbar'
  32. import browser from '@/util/browser'
  33. import {mapState} from 'vuex'
  34. export default {
  35. props: ['data'],
  36. computed: {
  37. ...mapState({
  38. language: state => state.language.current
  39. })
  40. },
  41. methods: {
  42. handleChange (nav) {
  43. setTimeout(async () => {
  44. let items = Array.from(this.$refs.dcon.querySelectorAll('img'))
  45. let offTop = 0
  46. items.forEach(item => {
  47. // item.style.background = '#fff'
  48. // let txt = item.querySelectorAll('span')[1].innerText
  49. if (String(item.alt) === String(nav.cover)) {
  50. offTop = item.offsetTop
  51. }
  52. })
  53. this.$refs.dcon.removeEventListener('scroll', this.listen)
  54. document.querySelector('#dcon').scrollTop = offTop
  55. let fixTop = Math.round(offTop / this.$refs.dcon.scrollHeight * 100)
  56. this.scorlltop = fixTop + '%'
  57. console.log(offTop)
  58. setTimeout(() => {
  59. this.$refs.dcon.addEventListener('scroll', this.listen)
  60. }, 500)
  61. }, 0)
  62. },
  63. listen (e) {
  64. let sTop = e.target.scrollTop
  65. let items = Array.from(this.$refs.dcon.querySelectorAll('img'))
  66. let active = ''
  67. let nav = ''
  68. items.forEach(item => {
  69. if (sTop > item.offsetTop - 1) {
  70. active = item.alt
  71. }
  72. })
  73. let fixTop = Math.round(sTop / this.$refs.dcon.scrollHeight * 100)
  74. this.scorlltop = fixTop + '%'
  75. this.navs.forEach(sub => {
  76. if (String(active) === String(sub.cover)) {
  77. nav = sub
  78. }
  79. })
  80. this.navActive = nav
  81. }
  82. },
  83. watch: {
  84. data: {
  85. immediate: false,
  86. deep: true,
  87. handler (newVal) {
  88. this.navs = this.data.data
  89. this.current = this.data.detail
  90. this.navActive = this.data.data[0]
  91. this.$refs.dcon.removeEventListener('scroll', this.listen)
  92. this.$refs.dcon.scrollTo(0, 0)
  93. setTimeout(() => {
  94. this.$refs.dcon.addEventListener('scroll', this.listen)
  95. }, 500)
  96. }
  97. }
  98. },
  99. data () {
  100. return {
  101. active: '',
  102. navs: this.data.data,
  103. current: this.data.detail,
  104. navActive: this.data.data[0],
  105. scorlltop: '0',
  106. isFireFox: browser.firefox
  107. }
  108. },
  109. mounted () {
  110. setTimeout(() => {
  111. this.$refs.dcon.addEventListener('scroll', this.listen)
  112. }, 0)
  113. },
  114. components: {lselect, scrollbar}
  115. }
  116. </script>
  117. <style lang="scss" scoped>
  118. $lw: 304px;
  119. $cw: 480px;
  120. $encw: 430px;
  121. .common-title {
  122. margin: 85px 0 65px;
  123. }
  124. .ls-outer{
  125. min-width: 220px;
  126. position: absolute;
  127. top: 0;
  128. left: 0;
  129. max-height: 100%;
  130. overflow: hidden;
  131. height: 100%;
  132. }
  133. .ls-scrollbar{
  134. height: calc(100vh - 380px);
  135. position: absolute;
  136. right: 0;
  137. top: 0;
  138. width: 10px;
  139. border-right: 1px solid #dcdcdc;
  140. }
  141. .ls-scroll-thumb{
  142. height: 50px;
  143. width: 5px;
  144. background-color: #ddd;
  145. border-radius: 5px;
  146. position: absolute;
  147. top: 0;
  148. right: 0;
  149. }
  150. .use-layout {
  151. position: relative;
  152. // max-width: 800px;
  153. // margin: 50px auto 72px;
  154. overflow: hidden;
  155. padding-left: $lw + 10px;
  156. padding-right: 10px;
  157. box-sizing: border-box;
  158. padding-bottom: 120px;
  159. .select {
  160. min-width: $lw;
  161. position: absolute;
  162. top: 0;
  163. left: 0;
  164. max-height: 590px;
  165. overflow-y: auto;
  166. height: 590px;
  167. }
  168. .firefox-select{
  169. min-width: $lw + 20px;
  170. }
  171. .img{
  172. margin-bottom: 20px;
  173. width: 100%;
  174. text-align: center;
  175. }
  176. .use-con{
  177. position: absolute;
  178. max-height: 100%;
  179. height: calc(100vh - 380px);
  180. overflow-y: auto;
  181. width: $cw;
  182. text-align: center;
  183. .img{
  184. &:last-of-type{
  185. margin-bottom: 200px;
  186. }
  187. }
  188. &::-webkit-scrollbar {
  189. width: 5px;
  190. height: 8px;
  191. }
  192. &::-webkit-scrollbar-thumb {
  193. height: 50px;
  194. background-color: rgba(221, 221, 221, 0.2);
  195. -webkit-border-radius: 4px;
  196. outline: 2px solid #fff;
  197. outline-offset: -2px;
  198. }
  199. &::-webkit-scrollbar-thumb:hover {
  200. height: 50px;
  201. background-color: #9f9f9f;
  202. -webkit-border-radius: 4px;
  203. }
  204. }
  205. }
  206. .en{
  207. max-width: 900px;
  208. padding-left: $lw + 158px;
  209. .use-con{
  210. width: $encw;
  211. }
  212. }
  213. </style>