我真的很困惑输入错误的结尾。我将其隔离为以下代码。当我删除代码时,错误消失了。
有人看到该错误可能与什么有关吗?控制台除了高亮显示结束脚本标记之外,没有指向其他特定内容。
<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>
答案 0 :(得分:0)
此代码有错误:
$('#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
});
答案 1 :(得分:0)
在script标记的末尾有两个关闭函数。删除其中一个并将其添加到“ 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>
答案 2 :(得分:0)
嗨,您在$ 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
});
答案 3 :(得分:0)
您未正确关闭功能,错过了功能结尾处的花括号,括号和分号。