electerious / basicScroll

Standalone parallax scrolling for mobile and desktop with CSS variables.
https://basicscroll.electerious.com
MIT License
3.63k stars 148 forks source link

Parallax image doesn't have the correct placement until the screen has been resized #48

Closed colossatr0n closed 5 years ago

colossatr0n commented 5 years ago

I'm using basicScroll with Angular through ngx-basicscroll. I'm able to get parallax working correctly, except for the initial parallax image placement. For some reason, the parallax image initially sits below where it should appear, but if I resize the screen even just a bit, it'll be at its correct placement.

Not sure if this is an Angular issue or a basicScroll issue.

Thanks.

colossatr0n commented 5 years ago

I was able to circumvent the issue by firing a resize event in ngOnInit after creating the basicScroll options:

ngOnInit() {
    this.modifier = 30;

    this.bsOptions = {
      from: 'top-bottom',
      to: 'bottom-top',
      track: true,
      props: {
        '--translateY': {
          from: 0,
          to: `${ 10 * this.modifier }px`,
          direct: true
        }
      }
    };
  window.dispatchEvent(new Event('resize'));
}