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 :: asp.net core 3.1 convert system.collections.generic.list`1[system.string] to javascript 
Javascript :: jquery get textarea text 
Javascript :: how to validate age above 18 in javascript 
Javascript :: html video autoplay not working 
Javascript :: javascript get device 
Javascript :: discord js how to mention bot 
Javascript :: push state array react 
Javascript :: vue select option get attribute 
Javascript :: mktime in js 
Javascript :: next router push state 
Javascript :: get the parent node from child node 
Javascript :: ajax delete laravel 
Javascript :: get current time in javascript 
Javascript :: spacebar event listener 
Javascript :: create array javascript numbers 
Javascript :: js string startswith ignore case 
Javascript :: remove animation css javascript 
Javascript :: remove element from array in an immutable way 
Javascript :: javascript clone array of objects 
Javascript :: js minifier api 
Javascript :: javascript const require 
Javascript :: open new tab with angular router 
Javascript :: difference between slice and splice 
Javascript :: iterate formData 
Javascript :: iterate through list js 
Javascript :: Javascript push a key value pair into a nested object array 
Javascript :: generate 50 random numbers between 1 and 500 in javascript 
Javascript :: clear arrays in jquery 
Javascript :: react native check os 
Javascript :: sql json_extract 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =