Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js scrollIntoView

const options = {
  inline: 'start',
  block: 'start',
  behavior: 'smooth'
}

htmlDiv.scrollIntoView(options)

/*
- behavior Optional
Defines the transition animation. One of auto or smooth. Defaults to auto.

- block Optional
Defines vertical alignment. One of start, center, end, or nearest.
Defaults to start.

- inline Optional
Defines horizontal alignment. One of start, center, end, or nearest. 
Defaults to nearest.
*/
Comment

scrollintoview javascript

// 1.
// <a class="nav__link" href="#section--1">Features</a>
document.querySelectorAll('.nav__link').forEach(item => {
  item.addEventListener('click', function (e) {
    e.preventDefault();
    document
      .querySelector(this.getAttribute('href'))
      .scrollIntoView({ behavior: 'smooth' });
  });
});

// 2.
// <ul class="nav__links"> ...
// <a class="nav__link" href="#section--1">Features</a>
document.querySelector('.nav__links').addEventListener('click', function (e) {
  e.preventDefault();
  if (e.target.classList.contains('nav__link')) {
    document
      .querySelector(e.target.getAttribute('href'))
      .scrollIntoView({ behavior: 'smooth' });
  }
});
Comment

scrollIntoView

const assert = require('assert')

describe('v5.webdriver.io', () => {

    it('should demonstrate the scrollIntoView command', async () => {

        await browser.url('https://v5.webdriver.io');

        const GitHub = await $('#footer [href="https://github.com/webdriverio/webdriverio"]')
        await GitHub.scrollIntoView();// scroll to specific element

        await browser.pause(4000);


    })    
    
    it('should demonstrate the scrollIntoView command', async () => {

        await browser.url('https://v5.webdriver.io');
        const getstarted = await $('[src="https://badge.fury.io/js/webdriverio.svg"]')
        await getstarted.scrollIntoView();// scroll to specific element

        await browser.pause(4000);
    
    })



})
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to use a debugger 
Javascript :: round to nearest step 
Javascript :: conditional rendering react 
Javascript :: react animation 
Javascript :: arrays 
Javascript :: Angular JS Interpolation 
Javascript :: for in and for of in js 
Javascript :: could not find react-redux context value; please ensure the component is wrapped in a <Provider 
Javascript :: sort javascript 
Javascript :: map and set in javascript 
Javascript :: express winston 
Javascript :: how to append an element to an array in javascript 
Javascript :: how to generate angular component with scss 
Javascript :: terjemahan 
Javascript :: assertion error in jest 
Javascript :: import module in ES6 
Javascript :: react autocomplete 
Javascript :: how to add alert on javascript 
Javascript :: react script syntax for deployment 
Javascript :: stripe payment js 
Javascript :: rxjs operators 
Javascript :: js array delete specific element 
Javascript :: materialze 
Javascript :: react in jquery 
Javascript :: web app let user confirm closing tab 
Javascript :: calculate init code hash nodejs 
Javascript :: Cannot GET /assets/vendor/swiper/swiper-bundle.min.js.map 
Javascript :: js array to scsv 
Javascript :: select all child elements javascript 
Javascript :: loader service show hide unit test angular 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =