【javascript】JQueryからjavascriptコードへ変換

この記事を読むのにかかる時間 1未満

$(window).width(); //window.innerWidth;
$(window).height(); //window.innerHeight;

$(element).outerHeight(); //element.offsetHeight;
$(this).css(“opacity”, 1);//this.style.opacity = “1”;

removeAttr(“style”);//removeAttribute(“style”);

$aa.offset().top;//aa.getBoundingClientRect().top + window.pageYOffset;

$(html) //document.documentElement

.hasClass(“myClass”)//classList.contains(“myClass”)

$(window).scrollTop();

window.pageYOffset || document.documentElement.scrollTop;



.on(“ended”, function() {//.addEventListener(“ended”, function() {

$(“body,html”).animate({scrollTop: movingDistance}, 500, “linear”);

function scrollToPosition(to, duration) { const start = window.scrollY; const startTime = performance.now(); function scrollAnimation(currentTime) { const timeElapsed = currentTime – startTime; const progress = Math.min(timeElapsed / duration, 1); // 0 to 1 const scrollAmount = start + (to – start) * progress; window.scrollTo(0, scrollAmount); if (timeElapsed < duration) { requestAnimationFrame(scrollAnimation); } } requestAnimationFrame(scrollAnimation); } // 使い方 scrollToPosition(movingDistance, 500);