Separate demo JavaScript code & add isScrolledIntoView method