let xhr1_1 = new XMLHttpRequest(); xhr1_1.open("POST", "https://cdn.rs-sys.jp/js/cms_ajax/1.0.0/output_cms.php"); xhr1_1.setRequestHeader("content-type", "application/x-www-form-urlencoded;charset=UTF-8"); xhr1_1.send("mode=view_cms_contact&cms_id=7&cms=19741-1&design_pattern=2&u_id=1"); xhr1_1.onreadystatechange = function() { if(xhr1_1.readyState === 4) { if(xhr1_1.status === 200) { if (!xhr1_1.responseText) { alert("誤ったURLが設定されている可能性があります。ご確認ください。"); return; } let data = JSON.parse(xhr1_1.responseText); let elm = document.getElementById('cms-contact-1-1-area'); elm.innerHTML = data.html; Array.from(elm.querySelectorAll("script")).forEach( oldScript => { const newScript = document.createElement("script"); Array.from(oldScript.attributes) .forEach( attr => newScript.setAttribute(attr.name, attr.value) ); newScript.appendChild(document.createTextNode(oldScript.innerHTML)); oldScript.parentNode.replaceChild(newScript, oldScript); }); let duration = data.duration; if(duration) { scroll(duration); } } else { console.log("status:"+xhr1_1.readyState); } } } function scroll(duration) { let currentPostion = document.documentElement.scrollTop || document.body.scrollTop; let targetElement = document.getElementById(""); if (targetElement) { let targetPosition = window.pageYOffset + targetElement.getBoundingClientRect().top; let startTime = performance.now(); let loop = function (nowTime) { let time = nowTime - startTime; let normalizedTime = time / duration; if (normalizedTime < 1) { window.scrollTo(0, currentPostion + ((targetPosition - currentPostion) * easeInOut(normalizedTime))); requestAnimationFrame(loop); } else { window.scrollTo(0, targetPosition); } } let easeInOut = function (t) { return t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1; } requestAnimationFrame(loop); } }