Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$fromDOMEvent can't listening root self scroll event #87

Closed
RyderJKL opened this issue Jun 14, 2018 · 5 comments
Closed

$fromDOMEvent can't listening root self scroll event #87

RyderJKL opened this issue Jun 14, 2018 · 5 comments

Comments

@RyderJKL
Copy link

RyderJKL commented Jun 14, 2018

I tried to listen for the scroll event on vm root, but it didn't work because $fromDOMEvent delegated the scroll event to document.documentElement, but the scroll event didn't bubble up, please see the following demo:

<template lang="pug">
  section.drag-container-wrapper
    section.drag-container
</template>

<script>
  import { Observable } from 'rxjs'
  import { pluck } from 'rxjs/operators'

  export default {
    subscriptions () {
      const rootScroll$ = this.$fromDOMEvent(null, 'scroll')
        .map(e => console.log(e))

      return {
        rootScroll$
      }
    }
  }
</script>

<style lang="stylus" scoped>
.drag-container-wrapper
  height 600px
  border 1px solid green
  overflow-y scroll
  padding 10px

.drag-container
  height 1600px
  border 1px solid red
</style>

Any ideas?

environment

vue: v2.5.2
rxjs: v6.0
vue-rx: v6.0.0
chrome: v67

@regou
Copy link
Collaborator

regou commented Jun 14, 2018

this.$fromDOMEvent(null, 'scroll') is this line correct?

@RyderJKL
Copy link
Author

RyderJKL commented Jun 16, 2018

@regou Is it not possible to add a scroll event in this way?
I made a simple demo on the CodeSandbox.
I successfully listened to the click, mousemove and other events on the container element through $fromDOMEvent, and even listened to the scroll event on the container via the mounted lifecycle, but using $fromDOMEvent would not work.

@regou
Copy link
Collaborator

regou commented Jun 16, 2018

subscriptions is called before created lifecycle, in that case the selector is unable to select the element
Try v-stream

@regou regou closed this as completed Jun 23, 2018
@arjamizo
Copy link

import { fromEvent } from 'rxjs'
// Vue instance
subscriptions() {
   scroll$: fromEvent(window, 'scroll'),
   consoleLog: this.scroll$.subscribe(msg => console.log(msg))
}

should work :)

@1shaked
Copy link

1shaked commented May 4, 2021

the error I get when I try to do this with nuxt.js and I added it as a plugin is the window is not defined

[Vue warn]: Error in created hook: "ReferenceError: window is not defined"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants