0
我想让浏览器滚动到页面上的一个点,如果页面向下滚动。我正在使用jQuery .bind()
将html
绑定到mousewheel
。这里是我的代码:为什么我的if语句继续运行?
"use strict";
var scrollpoint = 1;
$(document).ready(function(){
console.log(scrollpoint);
$("#divacon").hide();
$("#divbcon").hide();
$('#div-a').waypoint(function() {
$("#divacon").fadeIn();
var scrollpoint = 2;
console.log("waypoint a reached");
},{context:"#container"});
$('#div-b').waypoint(function() {
$("#divbcon").fadeIn();
console.log("waypoint b reached");
},{context:"#container"});
和
$('html').bind('mousewheel', function(e){
var flag = true;
if(flag) {
if(e.originalEvent.wheelDelta < 0) {
if((scrollpoint == 1)) {
var target = $('#div-a');
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
var targetoffset = target.offset().top;
console.log(scrollpoint);
$('#container').animate(
{scrollTop: targetoffset},
400,
function(){
var scrollpoint = 2;
console.log(scrollpoint);
}
);
}
else if((scrollpoint = 2)){
//scroll down
console.log('2');
}
else{
//scroll down
console.log('Down');
}
}else {
//scroll up
console.log('Up');
}
//prevent page fom scrolling
flag = false;
}
});
发生了什么事是我的if语句被调用后的第一时间,即使flag = false;
。我究竟做错了什么?该网站可以在现场http://wilsonbiggs.com/sandy
它不让我接受答案,但是,这是做到了!我是一个傻子,这很明显。哈哈 –
@WilsonBiggs:没问题。 – mithunsatheesh