0
我创建了一个带有JavaScript的滚动系统,用于我正在处理的网站,并且在排队所有输入时遇到了一些麻烦。从排队停止滚动功能
下面是我的问题的一个例子,尝试滚动,你会看到问题是什么。 http://fadedmeadows.com/test/
var index = 0;
var scroll2 = true;
$(document).ready(function() {
$("#home").css({
"color": "#eb0e0e",
});
});
$(window).bind('mousewheel DOMMouseScroll touchmove', function(event) {
scroll2 = true;
if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0) {
// scroll up
if (index > 4) index = 4;
if (index == 4 && scroll2 == true) {
$('html, body').animate({
scrollTop: $("#content3").offset().top
}, 1000);
index--;
scroll2 = false;
}
if (index == 3 && scroll2 == true) {
$('html, body').animate({
scrollTop: $("#content2").offset().top
}, 1000);
index--;
scroll2 = false;
}
if (index == 2 && scroll2 == true) {
$('html, body').animate({
scrollTop: $("#content").offset().top
}, 1000);
index--;
scroll2 = false;
}
if (index == 1 && scroll2 == true) {
$('html, body').animate({
scrollTop: $("header").offset().top
}, 1000);
index--;
scroll2 = false;
}
} else {
// scroll down
if (index < 0) index = 0;
if (index == 0 && scroll2 == true) {
$('html, body').animate({
scrollTop: $("#content").offset().top
}, 1000);
index++;
scroll2 = false;
}
if (index == 1 && scroll2 == true) {
$('html, body').animate({
scrollTop: $("#content2").offset().top
}, 1000);
index++;
scroll2 = false;
}
if (index == 2 && scroll2 == true) {
$('html, body').animate({
scrollTop: $("#content3").offset().top
}, 1000);
index++;
scroll2 = false;
}
if (index == 3 && scroll2 == true) {
$('html, body').animate({
scrollTop: $("#content4").offset().top
}, 1000);
index++;
scroll2 = false;
}
}
});
我是否能申报“等待“作为一个变量,仍然有这个代码工作?我已经使用类似的语言的JavaScript,所以这种方式奠定了对我来说没有意义。我觉得这是正确的轨道,但它不适合我,我需要尽快完成这个网站,提前谢谢你。 –
没关系我解决了这个问题,非常感谢你的帮助。我希望我可以upvote你,但它不会让我呢。 –
@KommanderKrunt没问题。所以IIUC,你能够将这种方法适用于你的用例?如果是这样,很酷!很高兴它帮助你:) –