two window scroll function conflicts and runs twice












0















How it looks:





This is like a mini scrollbar so




  1. dragging and dropping #draggable will trigger html scroll move.

  2. not using the scrollbar, when you scroll up or down #draggable automatically goes to a suitable position.


Problem occurs when I drag and drop #draggable, then html scroll moves, it triggers $(window).scroll(function(). #draggable goes up or down then goes to it's suitable position.






$(document).ready(function(){
$( "#draggable" ).draggable({axis: "y", grid: [ 0, 55 ], containment: "parent"});
var scrollT = $(document).scrollTop();
var visualT = $("#visual").offset().top;
var strengthT = $("#strength").offset().top;
var portfolioT = $("#portfolio").offset().top;
var contactT = $("#contact").offset().top;

$( "#droppable01" ).droppable({
drop: function(){
$('html, body').stop().animate({
scrollTop: $("#visual").offset().top
}, 1000);
}
});
$( "#droppable02" ).droppable({
drop: function(){
$('html, body').stop().animate({
scrollTop: $("#strength").offset().top
}, 1000);
}
});
$( "#droppable03" ).droppable({
drop: function(){
$('html, body').stop().animate({
scrollTop: $("#portfolio").offset().top
}, 1000);
}
});
$( "#droppable04" ).droppable({
drop: function(){
$('html, body').stop().animate({
scrollTop: $("#contact").offset().top
}, 1000);
}
});

$(window).scroll(function(){
if(scrollT < 1000){
$("#draggable").css({"top":"0px"});
}
if(scrollT >= 2000){
$("#draggable").css({"top":"55px"});
}
if(scrollT >= 3000){
$("#draggable").css({"top":"110px"});
}
if(scrollT >= 4000){
$("#draggable").css({"top":"165px"});
}
});
});

#pageDesc{width:16px; text-align:center; position:fixed; top:375px; right:75px; font-size:16px;}
#pageDesc p{height:175px; margin:20px 0; position:relative;}
#pageDesc .line{display:inline-block;width:1px; height:100%; background-color:#333; }
#draggable{z-index:3; display:block; width:9px; height:9px;border:1px solid #333; border-radius:100%; position:absolute; left:3px; top:0; transition:all 1s;}

/*#draggable.top0{top:0px;}
#draggable.top55{top:55px;}
#draggable.top110{top:110px;}
#draggable.top165{top:165px;}*/
#pageDesc ul{z-index:1;width:100%; height:100%; position:absolute;left:0; top:0;}
#pageDesc ul li{width:100%; height:24%; }

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
<div id="pageDesc">
01
<p>
<span class="line"></span>
<span class="point" id="draggable"></span>
</p>
04
<ul>
<li id="droppable01"></li>
<li id="droppable02"></li>
<li id="droppable03"></li>
<li id="droppable04"></li>
</ul>
</div>





I tried changing $("#draggable").css({"top":"0px"});




  1. to #draggable's attr('style', "top:;"); height.

  2. to $("#draggable").removeClass("top0 top110 top165") .addClass("top55");


and these don't work.










share|improve this question





























    0















    How it looks:





    This is like a mini scrollbar so




    1. dragging and dropping #draggable will trigger html scroll move.

    2. not using the scrollbar, when you scroll up or down #draggable automatically goes to a suitable position.


    Problem occurs when I drag and drop #draggable, then html scroll moves, it triggers $(window).scroll(function(). #draggable goes up or down then goes to it's suitable position.






    $(document).ready(function(){
    $( "#draggable" ).draggable({axis: "y", grid: [ 0, 55 ], containment: "parent"});
    var scrollT = $(document).scrollTop();
    var visualT = $("#visual").offset().top;
    var strengthT = $("#strength").offset().top;
    var portfolioT = $("#portfolio").offset().top;
    var contactT = $("#contact").offset().top;

    $( "#droppable01" ).droppable({
    drop: function(){
    $('html, body').stop().animate({
    scrollTop: $("#visual").offset().top
    }, 1000);
    }
    });
    $( "#droppable02" ).droppable({
    drop: function(){
    $('html, body').stop().animate({
    scrollTop: $("#strength").offset().top
    }, 1000);
    }
    });
    $( "#droppable03" ).droppable({
    drop: function(){
    $('html, body').stop().animate({
    scrollTop: $("#portfolio").offset().top
    }, 1000);
    }
    });
    $( "#droppable04" ).droppable({
    drop: function(){
    $('html, body').stop().animate({
    scrollTop: $("#contact").offset().top
    }, 1000);
    }
    });

    $(window).scroll(function(){
    if(scrollT < 1000){
    $("#draggable").css({"top":"0px"});
    }
    if(scrollT >= 2000){
    $("#draggable").css({"top":"55px"});
    }
    if(scrollT >= 3000){
    $("#draggable").css({"top":"110px"});
    }
    if(scrollT >= 4000){
    $("#draggable").css({"top":"165px"});
    }
    });
    });

    #pageDesc{width:16px; text-align:center; position:fixed; top:375px; right:75px; font-size:16px;}
    #pageDesc p{height:175px; margin:20px 0; position:relative;}
    #pageDesc .line{display:inline-block;width:1px; height:100%; background-color:#333; }
    #draggable{z-index:3; display:block; width:9px; height:9px;border:1px solid #333; border-radius:100%; position:absolute; left:3px; top:0; transition:all 1s;}

    /*#draggable.top0{top:0px;}
    #draggable.top55{top:55px;}
    #draggable.top110{top:110px;}
    #draggable.top165{top:165px;}*/
    #pageDesc ul{z-index:1;width:100%; height:100%; position:absolute;left:0; top:0;}
    #pageDesc ul li{width:100%; height:24%; }

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
    <div id="pageDesc">
    01
    <p>
    <span class="line"></span>
    <span class="point" id="draggable"></span>
    </p>
    04
    <ul>
    <li id="droppable01"></li>
    <li id="droppable02"></li>
    <li id="droppable03"></li>
    <li id="droppable04"></li>
    </ul>
    </div>





    I tried changing $("#draggable").css({"top":"0px"});




    1. to #draggable's attr('style', "top:;"); height.

    2. to $("#draggable").removeClass("top0 top110 top165") .addClass("top55");


    and these don't work.










    share|improve this question



























      0












      0








      0








      How it looks:





      This is like a mini scrollbar so




      1. dragging and dropping #draggable will trigger html scroll move.

      2. not using the scrollbar, when you scroll up or down #draggable automatically goes to a suitable position.


      Problem occurs when I drag and drop #draggable, then html scroll moves, it triggers $(window).scroll(function(). #draggable goes up or down then goes to it's suitable position.






      $(document).ready(function(){
      $( "#draggable" ).draggable({axis: "y", grid: [ 0, 55 ], containment: "parent"});
      var scrollT = $(document).scrollTop();
      var visualT = $("#visual").offset().top;
      var strengthT = $("#strength").offset().top;
      var portfolioT = $("#portfolio").offset().top;
      var contactT = $("#contact").offset().top;

      $( "#droppable01" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#visual").offset().top
      }, 1000);
      }
      });
      $( "#droppable02" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#strength").offset().top
      }, 1000);
      }
      });
      $( "#droppable03" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#portfolio").offset().top
      }, 1000);
      }
      });
      $( "#droppable04" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#contact").offset().top
      }, 1000);
      }
      });

      $(window).scroll(function(){
      if(scrollT < 1000){
      $("#draggable").css({"top":"0px"});
      }
      if(scrollT >= 2000){
      $("#draggable").css({"top":"55px"});
      }
      if(scrollT >= 3000){
      $("#draggable").css({"top":"110px"});
      }
      if(scrollT >= 4000){
      $("#draggable").css({"top":"165px"});
      }
      });
      });

      #pageDesc{width:16px; text-align:center; position:fixed; top:375px; right:75px; font-size:16px;}
      #pageDesc p{height:175px; margin:20px 0; position:relative;}
      #pageDesc .line{display:inline-block;width:1px; height:100%; background-color:#333; }
      #draggable{z-index:3; display:block; width:9px; height:9px;border:1px solid #333; border-radius:100%; position:absolute; left:3px; top:0; transition:all 1s;}

      /*#draggable.top0{top:0px;}
      #draggable.top55{top:55px;}
      #draggable.top110{top:110px;}
      #draggable.top165{top:165px;}*/
      #pageDesc ul{z-index:1;width:100%; height:100%; position:absolute;left:0; top:0;}
      #pageDesc ul li{width:100%; height:24%; }

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
      <div id="pageDesc">
      01
      <p>
      <span class="line"></span>
      <span class="point" id="draggable"></span>
      </p>
      04
      <ul>
      <li id="droppable01"></li>
      <li id="droppable02"></li>
      <li id="droppable03"></li>
      <li id="droppable04"></li>
      </ul>
      </div>





      I tried changing $("#draggable").css({"top":"0px"});




      1. to #draggable's attr('style', "top:;"); height.

      2. to $("#draggable").removeClass("top0 top110 top165") .addClass("top55");


      and these don't work.










      share|improve this question
















      How it looks:





      This is like a mini scrollbar so




      1. dragging and dropping #draggable will trigger html scroll move.

      2. not using the scrollbar, when you scroll up or down #draggable automatically goes to a suitable position.


      Problem occurs when I drag and drop #draggable, then html scroll moves, it triggers $(window).scroll(function(). #draggable goes up or down then goes to it's suitable position.






      $(document).ready(function(){
      $( "#draggable" ).draggable({axis: "y", grid: [ 0, 55 ], containment: "parent"});
      var scrollT = $(document).scrollTop();
      var visualT = $("#visual").offset().top;
      var strengthT = $("#strength").offset().top;
      var portfolioT = $("#portfolio").offset().top;
      var contactT = $("#contact").offset().top;

      $( "#droppable01" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#visual").offset().top
      }, 1000);
      }
      });
      $( "#droppable02" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#strength").offset().top
      }, 1000);
      }
      });
      $( "#droppable03" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#portfolio").offset().top
      }, 1000);
      }
      });
      $( "#droppable04" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#contact").offset().top
      }, 1000);
      }
      });

      $(window).scroll(function(){
      if(scrollT < 1000){
      $("#draggable").css({"top":"0px"});
      }
      if(scrollT >= 2000){
      $("#draggable").css({"top":"55px"});
      }
      if(scrollT >= 3000){
      $("#draggable").css({"top":"110px"});
      }
      if(scrollT >= 4000){
      $("#draggable").css({"top":"165px"});
      }
      });
      });

      #pageDesc{width:16px; text-align:center; position:fixed; top:375px; right:75px; font-size:16px;}
      #pageDesc p{height:175px; margin:20px 0; position:relative;}
      #pageDesc .line{display:inline-block;width:1px; height:100%; background-color:#333; }
      #draggable{z-index:3; display:block; width:9px; height:9px;border:1px solid #333; border-radius:100%; position:absolute; left:3px; top:0; transition:all 1s;}

      /*#draggable.top0{top:0px;}
      #draggable.top55{top:55px;}
      #draggable.top110{top:110px;}
      #draggable.top165{top:165px;}*/
      #pageDesc ul{z-index:1;width:100%; height:100%; position:absolute;left:0; top:0;}
      #pageDesc ul li{width:100%; height:24%; }

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
      <div id="pageDesc">
      01
      <p>
      <span class="line"></span>
      <span class="point" id="draggable"></span>
      </p>
      04
      <ul>
      <li id="droppable01"></li>
      <li id="droppable02"></li>
      <li id="droppable03"></li>
      <li id="droppable04"></li>
      </ul>
      </div>





      I tried changing $("#draggable").css({"top":"0px"});




      1. to #draggable's attr('style', "top:;"); height.

      2. to $("#draggable").removeClass("top0 top110 top165") .addClass("top55");


      and these don't work.






      $(document).ready(function(){
      $( "#draggable" ).draggable({axis: "y", grid: [ 0, 55 ], containment: "parent"});
      var scrollT = $(document).scrollTop();
      var visualT = $("#visual").offset().top;
      var strengthT = $("#strength").offset().top;
      var portfolioT = $("#portfolio").offset().top;
      var contactT = $("#contact").offset().top;

      $( "#droppable01" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#visual").offset().top
      }, 1000);
      }
      });
      $( "#droppable02" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#strength").offset().top
      }, 1000);
      }
      });
      $( "#droppable03" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#portfolio").offset().top
      }, 1000);
      }
      });
      $( "#droppable04" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#contact").offset().top
      }, 1000);
      }
      });

      $(window).scroll(function(){
      if(scrollT < 1000){
      $("#draggable").css({"top":"0px"});
      }
      if(scrollT >= 2000){
      $("#draggable").css({"top":"55px"});
      }
      if(scrollT >= 3000){
      $("#draggable").css({"top":"110px"});
      }
      if(scrollT >= 4000){
      $("#draggable").css({"top":"165px"});
      }
      });
      });

      #pageDesc{width:16px; text-align:center; position:fixed; top:375px; right:75px; font-size:16px;}
      #pageDesc p{height:175px; margin:20px 0; position:relative;}
      #pageDesc .line{display:inline-block;width:1px; height:100%; background-color:#333; }
      #draggable{z-index:3; display:block; width:9px; height:9px;border:1px solid #333; border-radius:100%; position:absolute; left:3px; top:0; transition:all 1s;}

      /*#draggable.top0{top:0px;}
      #draggable.top55{top:55px;}
      #draggable.top110{top:110px;}
      #draggable.top165{top:165px;}*/
      #pageDesc ul{z-index:1;width:100%; height:100%; position:absolute;left:0; top:0;}
      #pageDesc ul li{width:100%; height:24%; }

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
      <div id="pageDesc">
      01
      <p>
      <span class="line"></span>
      <span class="point" id="draggable"></span>
      </p>
      04
      <ul>
      <li id="droppable01"></li>
      <li id="droppable02"></li>
      <li id="droppable03"></li>
      <li id="droppable04"></li>
      </ul>
      </div>





      $(document).ready(function(){
      $( "#draggable" ).draggable({axis: "y", grid: [ 0, 55 ], containment: "parent"});
      var scrollT = $(document).scrollTop();
      var visualT = $("#visual").offset().top;
      var strengthT = $("#strength").offset().top;
      var portfolioT = $("#portfolio").offset().top;
      var contactT = $("#contact").offset().top;

      $( "#droppable01" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#visual").offset().top
      }, 1000);
      }
      });
      $( "#droppable02" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#strength").offset().top
      }, 1000);
      }
      });
      $( "#droppable03" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#portfolio").offset().top
      }, 1000);
      }
      });
      $( "#droppable04" ).droppable({
      drop: function(){
      $('html, body').stop().animate({
      scrollTop: $("#contact").offset().top
      }, 1000);
      }
      });

      $(window).scroll(function(){
      if(scrollT < 1000){
      $("#draggable").css({"top":"0px"});
      }
      if(scrollT >= 2000){
      $("#draggable").css({"top":"55px"});
      }
      if(scrollT >= 3000){
      $("#draggable").css({"top":"110px"});
      }
      if(scrollT >= 4000){
      $("#draggable").css({"top":"165px"});
      }
      });
      });

      #pageDesc{width:16px; text-align:center; position:fixed; top:375px; right:75px; font-size:16px;}
      #pageDesc p{height:175px; margin:20px 0; position:relative;}
      #pageDesc .line{display:inline-block;width:1px; height:100%; background-color:#333; }
      #draggable{z-index:3; display:block; width:9px; height:9px;border:1px solid #333; border-radius:100%; position:absolute; left:3px; top:0; transition:all 1s;}

      /*#draggable.top0{top:0px;}
      #draggable.top55{top:55px;}
      #draggable.top110{top:110px;}
      #draggable.top165{top:165px;}*/
      #pageDesc ul{z-index:1;width:100%; height:100%; position:absolute;left:0; top:0;}
      #pageDesc ul li{width:100%; height:24%; }

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
      <div id="pageDesc">
      01
      <p>
      <span class="line"></span>
      <span class="point" id="draggable"></span>
      </p>
      04
      <ul>
      <li id="droppable01"></li>
      <li id="droppable02"></li>
      <li id="droppable03"></li>
      <li id="droppable04"></li>
      </ul>
      </div>






      function scroll window drag






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 9:06









      barbsan

      2,35821222




      2,35821222










      asked Nov 22 '18 at 8:49









      Annie JinAnnie Jin

      11




      11
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426987%2ftwo-window-scroll-function-conflicts-and-runs-twice%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426987%2ftwo-window-scroll-function-conflicts-and-runs-twice%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Tonle Sap (See)

          I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

          Guatemaltekische Davis-Cup-Mannschaft