2014-03-27 3 views
0

페이지를 아래로 스크롤하면 브라우저에서 한 지점으로 스크롤하려고합니다. jQuery .bind()을 사용하여 htmlmousewheel에 바인딩합니다.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; 
    } 
}); 

는 무엇 일어나고있는 것은 그 내 문을 처음 후에 호출되는 경우에도 flag = false;입니다 : 여기에 내 코드입니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 이 사이트는 나는 그것이

var flag = true; //put the flag out side mouse wheel bind. 

$('html').bind('mousewheel', function(e){ 

    if(flag) { 

그렇지 않으면 당신도 트리거 할 때마다 당신이 flag true에 다음과 같은 if condition 항상 만족하실 것을 설정할 수 있다고 생각 http://wilsonbiggs.com/sandy

답변

2

라이브 찾을 수 있습니다.

+0

아직 답을 수락하지는 못하지만 예,이 문제가 해결되었습니다. 나는 돼지 고기 야. 이것은 아주 분명했다. 하하 –

+0

@WilsonBiggs : 문제 없습니다.! – mithunsatheesh

관련 문제