File: index.html

package info (click to toggle)
vue.js 2.6.12%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,124 kB
  • sloc: javascript: 80,436; sh: 97; makefile: 7
file content (105 lines) | stat: -rw-r--r-- 3,603 bytes parent folder | download | duplicates (2)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>Vue.js elastic header example</title>
    <!-- Delete ".min" for console warnings in development -->
    <script src="/javascript/vue/vue.min.js"></script>
    <script src="http://dynamicsjs.com/lib/dynamics.js"></script>
    <link rel="stylesheet" href="style.css">
    <!-- template for the component -->
    <script type="text/x-template" id="header-view-template">
      <div class="draggable-header-view"
        @mousedown="startDrag" @touchstart="startDrag"
        @mousemove="onDrag" @touchmove="onDrag"
        @mouseup="stopDrag" @touchend="stopDrag" @mouseleave="stopDrag">
        <svg class="bg" width="320" height="560">
          <path :d="headerPath" fill="#3F51B5"></path>
        </svg>
        <div class="header">
          <slot name="header"></slot>
        </div>
        <div class="content" :style="contentPosition">
          <slot name="content"></slot>
        </div>
      </div>
    </script>
  </head>
  <body>

    <div id="app" @touchmove.prevent>
      <draggable-header-view>
        <template slot="header">
          <h1>Elastic Draggable SVG Header</h1>
          <p>with <a href="https://vuejs.org">Vue.js</a> + <a href="http://dynamicsjs.com">dynamics.js</a></p>
        </template>
        <template slot="content">
          <p>Note this is just an effect demo - there are of course many additional details if you want to use this in production, e.g. handling responsive sizes, reload threshold and content scrolling. Those are out of scope for this quick little hack. However, the idea is that you can hide them as internal details of a Vue.js component and expose a simple Web-Component-like interface.</p>
        </template>
      </draggable-header-view>
    </div>

    <script>
    Vue.component('draggable-header-view', {
      template: '#header-view-template',
      data: function () {
        return {
          dragging: false,
          // quadratic bezier control point
          c: { x: 160, y: 160 },
          // record drag start point
          start: { x: 0, y: 0 }
        }
      },
      computed: {
        headerPath: function () {
          return 'M0,0 L320,0 320,160' +
            'Q' + this.c.x + ',' + this.c.y +
            ' 0,160'
        },
        contentPosition: function () {
          var dy = this.c.y - 160
          var dampen = dy > 0 ? 2 : 4
          return {
            transform: 'translate3d(0,' + dy / dampen + 'px,0)'
          }
        }
      },
      methods: {
        startDrag: function (e) {
          e = e.changedTouches ? e.changedTouches[0] : e
          this.dragging = true
          this.start.x = e.pageX
          this.start.y = e.pageY
        },
        onDrag: function (e) {
          e = e.changedTouches ? e.changedTouches[0] : e
          if (this.dragging) {
            this.c.x = 160 + (e.pageX - this.start.x)
            // dampen vertical drag by a factor
            var dy = e.pageY - this.start.y
            var dampen = dy > 0 ? 1.5 : 4
            this.c.y = 160 + dy / dampen
          }
        },
        stopDrag: function () {
          if (this.dragging) {
            this.dragging = false
            dynamics.animate(this.c, {
              x: 160,
              y: 160
            }, {
              type: dynamics.spring,
              duration: 700,
              friction: 280
            })
          }
        }
      }
    })

    new Vue({ el: '#app' })
    </script>
  </body>
</html>