Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Easy Angular way to detect if element is in viewport on scroll

// the element that you are observing (just add #yourElement in the template) for this  query to work
    @ViewChild('yourElement') yourElement: ElementRef;

    ngAfterViewInit() {
        const threshold = 0.2; // how much % of the element is in view
        const observer = new IntersectionObserver(
            (entries) => {
                entries.forEach((entry) => {
                    if (entry.isIntersecting) {
                        // run your animation code here
                        observer.disconnect(); // disconnect if you want to stop observing else it will rerun every time its back in view. Just make sure you disconnect in ngOnDestroy instead
                    }
                });
            },
            { threshold }
        );
        observer.observe(this.yourElement.nativeElement);
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: Angularjs onchange datetime picker not working 
Javascript :: object Promise showing instead of data pulled from API call 
Javascript :: Wait for AngularJS Service to finish running 
Javascript :: Presenting backend data using AngularJS/AJAX in MVC VIEW 
Javascript :: How to return $http.post() object with factory function 
Javascript :: Conditional navigation inside Tabs 
Javascript :: Display all posts from database 
Javascript :: Context: Cannot read properties of undefined 
Javascript :: how to make colspan of table footer flexible with javascript/jQuery 
Javascript :: adding to an array in js 
Javascript :: perl and regular expression for text extraction pdf 
Javascript :: sending api with limited fields in express 
Javascript :: error first callback in node js 
Javascript :: TypeError: table.fnFilter is not a function 
Javascript :: javascript encriment +1 
Javascript :: Printer Errors 
Javascript :: javascript assignment by reference or value 
Javascript :: phaser set mass 
Javascript :: Simple Cryptocurrency Blockchain Using JavaScript 
Javascript :: Declaring A Internal Method Of A Class 
Javascript :: javascript reverse string short hand 
Javascript :: open bootstrap modal from another modal 
Javascript :: Error: Invalid route module file 
Javascript :: how to get mempool transactions and decode with ethers js 
Javascript :: animation in react stack overflow 
Javascript :: var sumArray = function(arr) {}; 
Javascript :: Backbone Error: Uncaught TypeError: this.set is not a function 
Javascript :: clear an array 
Javascript :: java script strict mode 
Javascript :: number of factors 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =