This repository was archived by the owner on Jul 10, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +107
-0
lines changed Expand file tree Collapse file tree 5 files changed +107
-0
lines changed Original file line number Diff line number Diff line change 6363 "nuxt-client-init-module" : " ^0.1.4" ,
6464 "nuxt-env" : " ^0.1.0" ,
6565 "nuxt-property-decorator" : " ^2.1.3" ,
66+ "throttle-debounce" : " ^2.1.0" ,
6667 "ts-node" : " ^8.1.0" ,
6768 "vue-carousel" : " ^0.18.0" ,
6869 "vue-i18n" : " ^8.10.0" ,
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ section
5555 nuxt-link( to ='/example/routing-validate/true' ) routing-validate - validate is true
5656 p
5757 nuxt-link( to ='/example/routing-validate/false' ) routing-validate - validate is not true
58+ p
59+ nuxt-link( to ='/example/v-scroll' ) v-scroll
5860</template >
5961
6062<script lang="ts">
Original file line number Diff line number Diff line change 1+ <template lang="pug">
2+ section
3+ h1.title
4+ | v-scroll
5+ div
6+ h2.elem1 aaa
7+ div.center
8+ div
9+ h2( class ="elem2" , v-scroll ="handleScroll" ) bbb
10+ </template >
11+
12+ <script lang="ts">
13+ import { Component , Vue } from ' nuxt-property-decorator'
14+ import scroll from ' @/plugins/directives/scroll'
15+
16+ @Component ({
17+ directives: {
18+ scroll
19+ }
20+ })
21+ export default class extends Vue {
22+ public handleScroll(evt , el ) {
23+ // console.log(window.scrollY, el.scrollTop)
24+ const rect = el .getBoundingClientRect ().top
25+ if (rect < 950 ) {
26+ console .log (' 出現' )
27+ el .setAttribute (
28+ ' style' ,
29+ ' opacity: 1; transform: translate3d(0, -10px, 0)'
30+ )
31+
32+ return true
33+ }
34+ return false
35+ }
36+
37+ public head() {
38+ return {
39+ title: ' v-scroll'
40+ }
41+ }
42+ }
43+ </script >
44+
45+ <style lang="scss" scoped>
46+ .center {
47+ height : 1000px ;
48+ }
49+
50+ .elem1 {
51+ color : white ;
52+ background-color : #3b8070 ;
53+ }
54+
55+ .elem2 {
56+ color : white ;
57+ background-color : #526488 ;
58+ }
59+ </style >
Original file line number Diff line number Diff line change 1+ // .vue ファイルの中で Component に指定するなら以下の書き方を使う
2+ // import scroll from '@/plugins/directives/scroll';
3+ //
4+ // @Component ({
5+ // directives: {
6+ // scroll
7+ // }
8+ // })
9+
10+ import { throttle } from 'throttle-debounce'
11+
12+ export default {
13+ inserted : ( el , binding ) : void => {
14+ const f = throttle (
15+ 20 ,
16+ ( evt ) : void => {
17+ if ( binding . value ( evt , el ) ) {
18+ window . removeEventListener ( 'scroll' , f )
19+ }
20+ }
21+ )
22+
23+ window . addEventListener ( 'scroll' , f )
24+ }
25+ }
26+
27+ // nuxt.config.ts の plugin に定義するなら以下の書き方を使う
28+
29+ // import Vue from 'vue'
30+ //
31+ // Vue.directive('scroll', {
32+ // inserted: function(el, binding) {
33+ // let f = function(evt) {
34+ // if (binding.value(evt, el)) {
35+ // window.removeEventListener('scroll', f)
36+ // }
37+ // }
38+ // window.addEventListener('scroll', f)
39+ // }
40+ // })
Original file line number Diff line number Diff line change @@ -11764,6 +11764,11 @@ throat@^4.0.0:
1176411764 version "4.1.0"
1176511765 resolved "https://registry.yarnpkg.com/throat/-/throat-4.1.0.tgz#89037cbc92c56ab18926e6ba4cbb200e15672a6a"
1176611766
11767+ throttle-debounce@^2.1.0 :
11768+ version "2.1.0"
11769+ resolved "https://registry.yarnpkg.com/throttle-debounce/-/throttle-debounce-2.1.0.tgz#257e648f0a56bd9e54fe0f132c4ab8611df4e1d5"
11770+ integrity sha512-AOvyNahXQuU7NN+VVvOOX+uW6FPaWdAOdRP5HfwYxAfCzXTFKRMoIMk+n+po318+ktcChx+F1Dd91G3YHeMKyg==
11771+
1176711772through2@^2.0.0 :
1176811773 version "2.0.5"
1176911774 resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.5.tgz#01c1e39eb31d07cb7d03a96a70823260b23132cd"
You can’t perform that action at this time.
0 commit comments