Skip to content

Instantly share code, notes, and snippets.

@ndcunningham
Created September 3, 2019 14:00
Show Gist options
  • Save ndcunningham/646c372d975e8ec17189caceeef2da28 to your computer and use it in GitHub Desktop.
Save ndcunningham/646c372d975e8ec17189caceeef2da28 to your computer and use it in GitHub Desktop.
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
@ViewChild('dropZone', { static: true }) dropZone: ElementRef<HTMLDivElement>;
dragEnter$ = defer(() => fromEvent(this.dropZone.nativeElement, 'dragenter')).pipe(
tap((event: any) => { event.target.style.background = 'teal'; event.target.style.opacity = .5; })
);
dragExit$ = defer(() => fromEvent(this.dropZone.nativeElement, 'dragleave')).pipe(
tap((event: any) => { event.target.style.background = ''; event.target.style.opacity = 1; })
);
dragEnd$ = defer(() => fromEvent(this.dropZone.nativeElement, 'dragend')).pipe(
tap((event: any) => event.target.style.background = '')
);
ngOnInit() {
this.dragEnter$.subscribe();
this.dragEnd$.subscribe();
this.dragExit$.subscribe();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment