🕹 스크립트

js querySelectorAll 불러서 각각 setAttribute

(。θᗨθ。) 2022. 12. 15. 15:01
   const articleOdd = document.querySelectorAll('article.cont:nth-child(odd)');
   const articleEven = document.querySelectorAll('article.cont:nth-child(even)');

   for(let i = 0; i < articleOdd.length; i++){
    articleOdd[i].setAttribute("data-aos","fade-left");
   }
   for(let i = 0; i < articleEven.length; i++){
    articleEven[i].setAttribute("data-aos","fade-right");
   }
   
   // 동일
   const article = document.querySelectorAll('article.cont');

   for(let i = 0; i < article.length; i++){
    article[i].setAttribute("data-aos",i%2==0?"fade-left":"fade-right");
   }
728x90