[英]Unexpected End of Input Error on javascript
我真的很困惑我收到的輸入錯誤的結尾。 我將其隔離為以下代碼。 當我刪除代碼時,錯誤消失了。
有人看到錯誤可能與什么有關嗎? 除了突出顯示結束腳本標記之外,控制台沒有指向任何特定內容。
<script>
$(document).ready(function() {
//Arrow Down
$('#arrowDownWrap').click(function() {
$('html, body').animate({
scrollTop: $('#home-section2').offset().top -140}, 1000);
});
//Phone Img slide
let last_known_scroll_position = 0;
let ticking = false;
function doSomething(scroll_pos) {
// Do something with the scroll position
document.querySelector('#homeBoxGridRight img').style.transform = 'translateX(-' + (scroll_pos * 0.1) + '%)';
document.querySelector('#homeBoxGridRight img').style.transform += 'translateY(-50%)';
}
window.addEventListener('scroll', function(e) {
last_known_scroll_position = window.scrollY;
if (!ticking) {
window.requestAnimationFrame(function() {
doSomething(last_known_scroll_position);
ticking = false;
});
ticking = true;
}
});
});
</script>
此代碼有錯誤:
$('#arrowDownWrap').click(function() {
$('html, body').animate({
scrollTop: $('#home-section2').offset().top -140}, 1000);
});
這是解決方案:
$('#arrowDownWrap').click(function() {
$('html, body').animate({
scrollTop: $('#home-section2').offset().top -140}, 1000);
}); // <-- this line is missing
});
在腳本標記的末尾有兩個關閉函數。 刪除一個並將其添加到“ arrowDownWrap”函數之后,
您的代碼將如下所示:
<script>
$(document).ready(function() {
//Arrow Down
$('#arrowDownWrap').click(function() {
$('html, body').animate({
scrollTop: $('#home-section2').offset().top -140}, 1000);
});
});
//Phone Img slide
let last_known_scroll_position = 0;
let ticking = false;
function doSomething(scroll_pos) {
// Do something with the scroll position
document.querySelector('#homeBoxGridRight img').style.transform = 'translateX(-' + (scroll_pos * 0.1) + '%)';
document.querySelector('#homeBoxGridRight img').style.transform += 'translateY(-50%)';
}
window.addEventListener('scroll', function(e) {
last_known_scroll_position = window.scrollY;
if (!ticking) {
window.requestAnimationFrame(function() {
doSomething(last_known_scroll_position);
ticking = false;
});
ticking = true;
}
});
</script>
嗨,您在$ arrowDownWrap之后缺少結束標記,而是在腳本標記的上方兩次使用了結束標記。 祝你好運了。
window.addEventListener('scroll', function(e) {
last_known_scroll_position = window.scrollY;
if (!ticking) {
window.requestAnimationFrame(function() {
doSomething(last_known_scroll_position);
ticking = false;
});
ticking = true;
}
});
});//first remove this part here . It is repeated above which is giving you the error. IDE finds two endtags at the same point .
其次,在此處添加已刪除的結束標記並關閉您錯過的功能。 瞧。 祝好運
$('#arrowDownWrap').click(function() {
$('html, body').animate({
scrollTop: $('#home-section2').offset().top -140}, 1000);
}); // <-- this is where you missed it
});
您沒有正確關閉該功能,而錯過了該功能結束時的花括號,圓括號和分號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.