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 :: lodash find duplicate element index 
Javascript :: check if string is empty 
Javascript :: Get the url and parse or url.parse deprecated solved 
Javascript :: javascript es6 find 
Javascript :: empty check on django json field 
Javascript :: fetch post js 
Javascript :: js array index 
Javascript :: how to disable button in jquery 
Javascript :: command to run nextjs project 
Javascript :: js var vs let 
Javascript :: javascript search for words in sentence examples 
Javascript :: flutter http get json to map 
Javascript :: sequelize raw query 
Javascript :: Vue JS Production mode refresh causing 404 error 
Javascript :: JavaScript find the shortest word in a string 
Javascript :: react eslint 
Javascript :: regex scan youtube video id 
Javascript :: jquery scroll to position 
Javascript :: limit data with axios in react js 
Javascript :: delete an element to an array 
Javascript :: load more button javascript 
Javascript :: jquery timer countdown 
Javascript :: how to know the current route in react class component 
Javascript :: javascript regex match character from a set of characters 
Javascript :: js format string 2 digits 
Javascript :: jquery find input and select 
Javascript :: js falsy values 
Javascript :: ios/main.jsbundle no such file or directory react native 
Javascript :: expresiones regulares javascript 
Javascript :: react native webview disable touch 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =