Best JavaScript code snippet using taiko
script.js
Source:script.js
1"use strict";23document.addEventListener('DOMContentLoaded', () => {4 const hamburger = document.querySelector('.hamburger'),5 menu = document.querySelector('.menu'),6 closeElem = document.querySelector('.menu__close');78 hamburger.addEventListener('click', () => {9 menu.classList.add('active');10 menu.classList.remove('animate__rollOut');11 menu.classList.add('animate__rollIn');12 13 });1415 closeElem.addEventListener('click', () => {16 menu.classList.remove('active');17 menu.classList.remove('animate__rollIn');18 menu.classList.add("animate__rollOut");19 });20 21 // color22 const red = document.querySelector(".menu__red"),23 green = document.querySelector(".menu__green"),24 blue = document.querySelector(".menu__blue"),25 orange= document.querySelector(".menu__orange"),26 painter= document.querySelector(".menu__painter");27 28 red.addEventListener('click', () => { 29 document.documentElement.style.setProperty('--main-color', '#bd3a3a');30 painter.style = red;31 });32 green.addEventListener('click', () => {33 document.documentElement.style.setProperty('--main-color', '#52d652'); 34 });35 blue.addEventListener('click', () => {36 document.documentElement.style.setProperty('--main-color', '#01C2FF'); 37 });38 orange.addEventListener('click', () => {39 document.documentElement.style.setProperty('--main-color', '#f89e16'); 40 });41 42 //progress43 const progress = document.querySelectorAll(".skills__progress-counter"),44 lines = document.querySelectorAll(".skills__progress-line span");45 progress.forEach((item, i) => {46 lines[i].style.width = item.innerHTML;47 }); 4849 // validate5051 const form = document.querySelector(".contacts__form"),52 name = document.querySelector(".contacts__name input"),53 email = document.querySelector(".contacts__email input"),54 policy = document.querySelector(".contacts__policy"),55 policyInput = policy.querySelector("input"),56 divName = document.createElement("div"),57 divEmail = document.createElement("div"),58 divPolicy = document.createElement("div"),59 status = document.querySelector("#my-form-status");60 let nameValide = false,61 emailValide = false,62 policyValide = false;63 function inputStyle(input) {64 input.style.cssText = `65 font-size: 13px;66 color: #000;67 margin-top: 5px;68 font-weight: bold;69 `;70 }71 const postData = async (url, data) => {72 let res = await fetch(url, {73 method: form.method,74 body: data,75 headers: {76 'Accept': 'application/json'77 }78 });7980 if (!res.ok) {81 status.innerHTML = "Oops! There was a problem submitting your form";82 throw new Error(`Could not fetch ${url}, status: ${res.status}`);83 }84 return await res.json(); 8586 };87 form.addEventListener('submit', function(e) {88 e.preventDefault();89 const data = new FormData(e.target);9091 if (name.value){92 if(name.value.length >= 5 && (/\d/i).test(name.value) == false && (/\s/i).test(name.value) == true && (name.value).search(/\s/i) != name.value.length-1) {93 divName.textContent = "";94 name.style.border = "none";95 nameValide = true;96 } else {97 name.style.border = "3px solid red";98 divName.textContent = "Ðоле непÑавилÑно заполнено.";99 inputStyle(divName);100 name.after(divName);101 nameValide = false;102 }103 } else {104 nameValide = false;105 name.style.border = "3px solid red";106 divName.textContent = "ÐведиÑе ваÑе имÑ.";107 name.after(divName);108 inputStyle(divName);109 }110111 if (email.value) {112 if ((/@/i).test(email.value) && ((/.ua/i).test(email.value) || (/.com/i).test(email.value) || (/.ill/i).test(email.value) || (/.net/i).test(email.value) || (/.gov/i).test(email.value) || (/.co/i).test(email.value) || (/.org/i).test(email.value) || (/.us/i).test(email.value) || (/.con/i).test(email.value))) {113 divEmail.textContent = "";114 email.style.border = "none";115 emailValide = true;116 } else {117 email.style.border = "3px solid red";118 divEmail.textContent = "Ðоле непÑавилÑно заполнено.";119 inputStyle(divEmail);120 email.after(divEmail);121 emailValide = false;122 }123 } else {124 emailValide = false;125 email.style.border = "3px solid red";126 divEmail.textContent = "ÐведиÑе Ð²Ð°Ñ email.";127 email.after(divEmail);128 inputStyle(divEmail);129 }130131 if (policyInput.checked) {132 divPolicy.style.display = "none";133 policyValide = true;134 policy.style.border = "none";135 } else {136 policyValide = false;137 policy.style.border = "3px solid red";138 divPolicy.textContent = "ÐведиÑе V";139 policyInput.before(divPolicy);140 divPolicy.style.cssText = `141 font-size: 13px;142 color: #000;143 margin-top: -20px;144 font-weight: bold; 145 `;146 }147 if (nameValide && emailValide && policyValide) {148 postData(form.action, data)149 .then(response => {150 status.innerHTML = "СпаÑибо за ÑообÑение!";151 }).catch(error => {152 status.innerHTML = "Ðй! ÐÑи оÑпÑавке ÑоÑÐ¼Ñ Ð²Ð¾Ð·Ð½Ð¸ÐºÐ»Ð° пÑоблема";153 }).finally(()=>{154 e.target.reset();155 });156 } 157 });158 159160161162163164165166167 //animation168169 new WOW().init();170171172 // sidepanel173 function offset(a) { 174 for (var b = 0; a;) {175 b += parseInt(a.offsetTop); 176 a = a.offsetParent;177 return b;178 }179 }180 let s = !0;181 window.onload = function () {182 const a = document.querySelector(".sidepanel"),183 b = offset(a),184 f = window.getComputedStyle ? getComputedStyle(a, "") : a.currentStyle, 185 d = a.offsetHeight + parseInt(f.marginTop) || 0,186 e = offset(document.querySelector(".price"));187 188 window.onscroll = function () {189 var c = window.pageYOffset || document.documentElement.scrollTop;190 c = e - (c + d + b);191 s != 0 < c && ((s = 0 < c) ? (a.style.top = b + "px", a.style.position = "fixed") : (a.style.top = e - d + "px", a.style.position = "absolute")); 192 };193 };194 195 196 197 // pageUp198 const scrollPageUp = document.querySelector(".pageup");199 function scrollFunction() {200 if (document.documentElement.scrollTop > 2000) {201 scrollPageUp.style.display = "block";202 } else {203 scrollPageUp.style.display = "none";204 }205 }206 window.addEventListener("scroll", ()=>{207 scrollFunction();208 });209 function myAnimation() {210 console.log(2);211 document.documentElement.scrollBy(0,-50);212 if (document.documentElement.scrollTop > 0 ) {213 requestAnimationFrame(myAnimation);214 }215 }216 scrollPageUp.addEventListener("click", () => {217 requestAnimationFrame(myAnimation);218 console.log(1);219 }); 220
...
pc.js
Source:pc.js
1let fullPage = document.body;2let scrollPageUp = "scroll-page-up";3let scrollPageDown = "scroll-page-down";4let scrollVal = 0;5// window.addEventListener("scroll", () => {6// let searchBlock = $$('.search-block')[0];7// scrollSearchBlock = "scroll-search-block";8//9// let currentScroll = window.pageYOffset;10// if (currentScroll <= 0) {debugger11// fullPage.classList.remove(scrollPageUp);12// searchBlock.classList.remove(scrollSearchBlock);13// return;14// }15// if (currentScroll > scrollVal && !fullPage.classList.contains(scrollPageDown)) {debugger16// fullPage.classList.remove(scrollPageUp);17// fullPage.classList.add(scrollPageDown);18// searchBlock.classList.remove(scrollSearchBlock);19// } else if (currentScroll < scrollVal && fullPage.classList.contains(scrollPageDown)) {debugger20// fullPage.classList.remove(scrollPageDown);21// fullPage.classList.add(scrollPageUp);22// searchBlock.classList.add(scrollSearchBlock);23// }24// scrollVal = currentScroll;25// });26let searchClickBg = $$('.search-bg')[0];27searchClickBg.addEventListener('click',function (e) {28 if(!e.target.classList.contains('open-search-block')){29 let openedSearchBlock = document.getElementsByClassName('search-block');30 let iconSearch = $$('.icon-search')[0];31 if(openedSearchBlock.length != 0) {32 openedSearchBlock[0].classList.remove('open-search-block');33 iconSearch.style.display = 'inline-block';34 }35 }36})37function searchToggle(){38 let searchBlock = $$('.search-block')[0];39 let searchBg = $$('.search-bg')[0];40 let closeBtn = $$('.search-close-btn')[0];41 let iconSearch = $$('.icon-search')[0];42 if(searchBlock.classList.contains('open-search-block')) {43 searchBlock.classList.remove('open-search-block');44 closeBtn.style.display = 'none';45 iconSearch.style.display = 'inline-block';46 } else {47 searchBlock.classList.add('open-search-block');48 closeBtn.style.display = 'block';49 iconSearch.style.display = 'none';50 }51}52document.addEventListener('DOMContentLoaded', function(){53 var favorites = localStorage.getItem('vzo');54 if(favorites != null) {55 favorites = favorites.split(',');56 if(favorites.length != 0){57 $$('.fav-items-count')[0].innerHTML = favorites.length;58 $$('.fav-items-count')[0].style.display = 'flex';59 $$('.icon-for-show-notice')[0].classList.add('show-favorites-cards');60 }61 }62 // var compareItems = localStorage.getItem('vzo_compare'+window.CATEGORY_ID);63 var compareItems = null;64 for (let i = 1; i < 12; i++) {65 var compareItemsByCat = localStorage.getItem('vzo_compare' + i);66 if (compareItemsByCat != null) {67 compareItems += compareItemsByCat.split(',').length;68 }69 }70 if($$('.compare-items-count').length != 0) {71 var compareItemsCountBlock = $$('.compare-items-count')[0];72 if(compareItems != null) {73 compareItemsCountBlock.innerHTML = compareItems;74 compareItemsCountBlock.style.display = 'flex';75 $$('.icon-for-show-notice')[0].classList.add('show-favorites-cards');76 } else {77 compareItemsCountBlock.style.display = 'none';78 }79 }...
BackToTopButton.js
Source:BackToTopButton.js
1import React, {useEffect, useState} from 'react';2import { ScrollToTopBtn } from '../Button/style';3import { FiArrowUp } from "react-icons/fi";4const BackToTopButton = () => {5 const [toTop, setToTop] = useState(false);6 useEffect(() => {7 window.addEventListener("scroll", toggleScrollButton);8 return () => {9 window.removeEventListener("scroll", toggleScrollButton);10 }11 }, []);12 const toggleScrollButton = () => {13 if (window.scrollY > 100) {14 setToTop(true);15 } else {16 setToTop(false);17 }18 }19 const scrollPageUp = () => {20 window.scrollTo({21 top: 0,22 behavior: "smooth"23 });24 };25 return (26 <>27 {toTop ?28 <ScrollToTopBtn onClick={scrollPageUp}>29 <FiArrowUp />30 </ScrollToTopBtn> : null}31 </>32 );33 34}...
Using AI Code Generation
1const { scrollPageUp } = require('taiko');2(async () => {3 await scrollPageUp();4})();5const { scrollPageDown } = require('taiko');6(async () => {7 await scrollPageDown();8})();9const { scrollLeft } = require('taiko');10(async () => {11 await scrollLeft();12})();13const { scrollRight } = require('taiko');14(async () => {15 await scrollRight();16})();17const { scrollTo } = require('taiko');18(async () => {19 await scrollTo('text');20})();21const { scrollUp } = require('taiko');22(async () => {23 await scrollUp();24})();25const { scrollDown } = require('taiko');26(async () => {27 await scrollDown();28})();29const { scrollRight } = require('taiko');30(async () => {31 await scrollRight();32})();33const { scrollLeft } = require('taiko');34(async () => {35 await scrollLeft();36})();37const { scrollTo } = require('taiko');38(async () => {39 await scrollTo('text');40})();41const { scrollUp } = require('taiko');42(async () => {43 await scrollUp();44})();45const { scrollDown } = require('taiko');46(async () => {47 await scrollDown();48})();49const { scrollTo } = require('taiko');50(async () => {51 await scrollTo('text');52})();53const {
Using AI Code Generation
1const { scrollPageUp } = require('taiko');2(async () => {3 try {4 await scrollPageUp();5 } catch (e) {6 console.error(e);7 } finally {8 }9})();
Using AI Code Generation
1const { scrollPageUp } = require('taiko');2(async () => {3 try {4 await scrollPageUp();5 } catch (error) {6 console.error(error);7 }8})();9const { scrollPageDown } = require('taiko');10(async () => {11 try {12 await scrollPageDown();13 } catch (error) {14 console.error(error);15 }16})();17const { scrollTo, button } = require('taiko');18(async () => {19 try {20 await scrollTo(button('Click me'));21 } catch (error) {22 console.error(error);23 }24})();25const { scrollRight } = require('taiko');26(async () => {27 try {28 await scrollRight();29 } catch (error) {30 console.error(error);31 }32})();33const { scrollLeft } = require('taiko');34(async () => {35 try {36 await scrollLeft();37 } catch (error) {38 console.error(error);39 }40})();41const { tap, button } = require('taiko');42(async () => {43 try {44 await tap(button('Click me'));45 } catch (error) {46 console.error(error);47 }48})();49const { doubleClick, button } = require('taiko');50(async () => {51 try {52 await doubleClick(button('Click me'));53 }
Using AI Code Generation
1scrollPageUp();2scrollPageDown();3scrollTo(100);4scrollTo({x:100,y:100});5scrollTo('text');6scrollTo('text',100);7scrollTo('text',{x:100,y:100});8scrollTo({selector:'text',index:1});9scrollTo({selector:'text',index:1},100);10scrollTo({selector:'text',index:1},{x:100,y:100});11scrollTo({selector:'text',index:1},100,{x:100,y:100});12scrollTo({selector:'text',index:1},{selector:'text',index:1});13scrollTo({selector:'text',index:1},{selector:'text',index:1},100);14scrollTo({selector:'text',index:1},{selector:'text',index:1},{x:100,y:100});15scrollTo({selector:'text',index:1},{selector:'text',index:1},100,{x:100,y:100});16scrollTo({selector:'text',index:1},100,{selector:'text',index:1});17scrollTo({selector:'text',index:1},100,{selector:'text
Using AI Code Generation
1scrollPageUp();2scrollPageDown();3scrollRight();4scrollLeft();5scrollUp();6scrollDown();7scrollTo("Get Started");8scrollIntoView("Get Started");9tap("Get Started");10doubleClick("Get Started");11rightClick("Get Started");12mouseOver("Get Started");13focus("Get Started");14write("Taiko", into("Search"));
Using AI Code Generation
1scrollPageUp();2scrollPageDown();3scrollTo("element");4scrollRight(100);5scrollLeft(100);6tap("element");7doubleTap("element");8rightClick("element");9focus("element");10write("text","element");11clear("element");12attach("file","element");13press("key");
Using AI Code Generation
1await scrollPageUp();2await scrollPageDown();3await scrollTo('linkText');4await scrollToBottom();5await scrollToTop();6await screenshot({ path: 'screenshot.png' });7await tap('linkText');8await text('linkText');9await textBox('linkText');10await title();11await toRightOf('linkText');12await toLeftOf('linkText');
Using AI Code Generation
1const { scrollPageUp } = require('taiko');2scrollPageUp();3const { scrollPageDown } = require('taiko');4scrollPageDown();5const { scrollDown } = require('taiko');6scrollDown('div');7const { scrollUp } = require('taiko');8scrollUp('div');9const { scrollTo } = require('taiko');10scrollTo('div', 'bottom');11const { scrollRight } = require('taiko');12scrollRight('div');13const { scrollLeft } = require('taiko');14scrollLeft('div');15const { tap } = require('taiko');16tap('div');17const { doubleTap } = require('taiko');18doubleTap('div');19const { rightClick } = require('taiko');20rightClick('div');21const { focus }
Using AI Code Generation
1scrollPageUp();2scrollPageDown();3scrollDown(100);4scrollUp(100);5scrollTo("Login");6scrollToRight(100);7scrollToLeft(100);8scrollRight(100);9scrollLeft(100);10tap("Login");11doubleTap("Login");12rightClick("Login");13focus("Login");
Using AI Code Generation
1scrollPageUp();2scrollPageUp(100);3scrollPageUp(100, { speed: 100 });4scrollPageUp(100, { speed: 100, timeout: 1000 });5scrollPageUp(100, { speed: 100, timeout: 1000, waitForNavigation: true });6scrollPageUp(100, { speed: 100, timeout: 1000, waitForNavigation: true, navigationTimeout: 1000 });7scrollPageUp(100, { speed: 100, timeout: 1000, waitForNavigation: true, navigationTimeout: 1000, horizontal: true });8scrollPageUp(100, { speed: 100, timeout: 1000, waitForNavigation: true, navigationTimeout: 1000, horizontal: true, repeat: 3 });9scrollPageDown();10scrollPageDown(100);11scrollPageDown(100, { speed: 100 });12scrollPageDown(100, { speed: 100, timeout: 1000 });13scrollPageDown(100, { speed: 100, timeout: 1000, waitForNavigation: true });14scrollPageDown(100, { speed: 100, timeout: 1000, waitForNavigation: true, navigationTimeout: 1000 });15scrollPageDown(100, { speed: 100, timeout: 1000, waitForNavigation: true, navigationTimeout: 1000, horizontal: true });16scrollPageDown(100, { speed: 100, timeout: 1000, waitForNavigation: true, navigationTimeout: 1000, horizontal: true, repeat: 3 });17scrollUp();18scrollUp(100);19scrollUp(100, { speed: 100 });20scrollUp(100, { speed: 100, timeout: 1000 });21scrollUp(100, { speed: 100, timeout: 1000, waitForNavigation: true });22scrollUp(100, { speed: 100, timeout: 1000, waitForNavigation: true, navigationTimeout: 1000 });23scrollUp(100, { speed: 100, timeout: 1000, waitForNavigation: true, navigationTimeout: 1000, horizontal: true });24scrollUp(100, { speed: 100, timeout: 1000, waitForNavigation: true, navigation
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!