liuxiaolong
2019-05-06 8700cf1dc46c350371d865532c2914595187788e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import layoutHelpers from '@/layout/helpers.js'
 
export default function () {
  return {
    // Layout helpers
    layoutHelpers,
 
    // Check for RTL layout
    get isRTL () {
      return document.documentElement.getAttribute('dir') === 'rtl' ||
             document.body.getAttribute('dir') === 'rtl'
    },
 
    // Check if IE
    get isIE () {
      return typeof document['documentMode'] === 'number'
    },
 
    // Check if IE10
    get isIE10 () {
      return this.isIE && document['documentMode'] === 10
    },
 
    // Layout navbar color
    get layoutNavbarBg () {
      return 'navbar-theme'
    },
 
    // Layout sidenav color
    get layoutSidenavBg () {
      return 'sidenav-theme'
    },
 
    // Layout footer color
    get layoutFooterBg () {
      return 'footer-theme'
    },
 
    // Animate scrollTop
    scrollTop (to, duration, element = document.scrollingElement || document.documentElement) {
      if (element.scrollTop === to) return
      const start = element.scrollTop
      const change = to - start
      const startDate = +new Date()
 
      // t = current time; b = start value; c = change in value; d = duration
      const easeInOutQuad = (t, b, c, d) => {
        t /= d / 2
        if (t < 1) return c / 2 * t * t + b
        t--
        return -c / 2 * (t * (t - 2) - 1) + b
      }
 
      const animateScroll = () => {
        const currentDate = +new Date()
        const currentTime = currentDate - startDate
        element.scrollTop = parseInt(easeInOutQuad(currentTime, start, change, duration))
        if (currentTime < duration) {
          requestAnimationFrame(animateScroll)
        } else {
          element.scrollTop = to
        }
      }
 
      animateScroll()
    }
  }
}