recursion in scroll triggered conditionals2019 Community Moderator ElectionHow to Check if element is visible after scrolling?Scroll to the top of the page using JavaScript/jQuery?jQuery multiple events to trigger the same functionjQuery scroll to elementjQuery scrolling DIV: stop scrolling when DIV reaches footerSticky Sidebar - Scroll Through Sidebar Then StickSticky sidebar: stick to bottom when scrolling down, top when scrolling upjQuery's jquery-1.10.2.min.map is triggering a 404 (Not Found)Floating, scrolling element is changing scroll positionjQuery fade main page content (#main) at top as user scrolls down

Meaning of "SEVERA INDEOVI VAS" from 3rd Century slab

Possible Leak In Concrete

Bash replace string at multiple places in a file from command line

Be in awe of my brilliance!

What does it mean to make a bootable LiveUSB?

2D counterpart of std::array in C++17

Why do Australian milk farmers need to protest supermarkets' milk price?

Life insurance that covers only simultaneous/dual deaths

Why are the outputs of printf and std::cout different

An Accountant Seeks the Help of a Mathematician

What options are left, if Britain cannot decide?

What is IP squat space

Does this AnyDice function accurately calculate the number of ogres you make unconcious with three 4th-level castings of Sleep?

How could a scammer know the apps on my phone / iTunes account?

How do I hide Chekhov's Gun?

Is it possible that AIC = BIC?

Why using two cd commands in bash script does not execute the second command

Employee lack of ownership

Theorems like the Lovász Local Lemma?

Good allowance savings plan?

Is it true that real estate prices mainly go up?

Make a transparent 448*448 image

Identifying the interval from A♭ to D♯

Pinhole Camera with Instant Film



recursion in scroll triggered conditionals



2019 Community Moderator ElectionHow to Check if element is visible after scrolling?Scroll to the top of the page using JavaScript/jQuery?jQuery multiple events to trigger the same functionjQuery scroll to elementjQuery scrolling DIV: stop scrolling when DIV reaches footerSticky Sidebar - Scroll Through Sidebar Then StickSticky sidebar: stick to bottom when scrolling down, top when scrolling upjQuery's jquery-1.10.2.min.map is triggering a 404 (Not Found)Floating, scrolling element is changing scroll positionjQuery fade main page content (#main) at top as user scrolls down










0















When I use the code below, when I scroll the sidebar flashes back and forth. testing found that it is because the winTop >= (contentTop - header.height()) condition fails every other scroll iteration.



The idea is that there is a sidebar on the page that sticks on scroll until it hits the footer, then it positions absolutely to the bottom of its container until scrolling back up.



It does everything correctly except that condition fails every other "click" of the scroll wheel, causing the sidebar to flash violently.



Here is a live example: http://www-icoachfirst-com.sandbox.hs-sites.com/test-lptest-lp



jquery:



var $window = $(window),
header = $('.header'),
sidebar = $('#sidebar'),
content = $('#content'),
container = $('.floattrap'),
footer = $('.footer_main');

$(window).on('load scroll resize', function()
var contentTop = sidebar.offset().top,
winTop = $(window).scrollTop(),
footerTop = footer.offset().top;

console.log(winTop);
if (winTop >= (contentTop - header.height()))

if (footerTop <= (winTop + $window.height()))
sidebar.removeClass('stuck');
sidebar.addClass('bot');
console.log(true);
else
sidebar.removeClass('bot');
sidebar.addClass('stuck');

$('.stuck').css(
'top': (header.outerHeight(true) + 20),
'left': (content.offset().left + content.width()),
'right': (container.offset().left + container.width())
);

console.log(false);


else
console.log('fail');
sidebar.removeClass('stuck');
sidebar.removeClass('bot');

);









share|improve this question


























    0















    When I use the code below, when I scroll the sidebar flashes back and forth. testing found that it is because the winTop >= (contentTop - header.height()) condition fails every other scroll iteration.



    The idea is that there is a sidebar on the page that sticks on scroll until it hits the footer, then it positions absolutely to the bottom of its container until scrolling back up.



    It does everything correctly except that condition fails every other "click" of the scroll wheel, causing the sidebar to flash violently.



    Here is a live example: http://www-icoachfirst-com.sandbox.hs-sites.com/test-lptest-lp



    jquery:



    var $window = $(window),
    header = $('.header'),
    sidebar = $('#sidebar'),
    content = $('#content'),
    container = $('.floattrap'),
    footer = $('.footer_main');

    $(window).on('load scroll resize', function()
    var contentTop = sidebar.offset().top,
    winTop = $(window).scrollTop(),
    footerTop = footer.offset().top;

    console.log(winTop);
    if (winTop >= (contentTop - header.height()))

    if (footerTop <= (winTop + $window.height()))
    sidebar.removeClass('stuck');
    sidebar.addClass('bot');
    console.log(true);
    else
    sidebar.removeClass('bot');
    sidebar.addClass('stuck');

    $('.stuck').css(
    'top': (header.outerHeight(true) + 20),
    'left': (content.offset().left + content.width()),
    'right': (container.offset().left + container.width())
    );

    console.log(false);


    else
    console.log('fail');
    sidebar.removeClass('stuck');
    sidebar.removeClass('bot');

    );









    share|improve this question
























      0












      0








      0








      When I use the code below, when I scroll the sidebar flashes back and forth. testing found that it is because the winTop >= (contentTop - header.height()) condition fails every other scroll iteration.



      The idea is that there is a sidebar on the page that sticks on scroll until it hits the footer, then it positions absolutely to the bottom of its container until scrolling back up.



      It does everything correctly except that condition fails every other "click" of the scroll wheel, causing the sidebar to flash violently.



      Here is a live example: http://www-icoachfirst-com.sandbox.hs-sites.com/test-lptest-lp



      jquery:



      var $window = $(window),
      header = $('.header'),
      sidebar = $('#sidebar'),
      content = $('#content'),
      container = $('.floattrap'),
      footer = $('.footer_main');

      $(window).on('load scroll resize', function()
      var contentTop = sidebar.offset().top,
      winTop = $(window).scrollTop(),
      footerTop = footer.offset().top;

      console.log(winTop);
      if (winTop >= (contentTop - header.height()))

      if (footerTop <= (winTop + $window.height()))
      sidebar.removeClass('stuck');
      sidebar.addClass('bot');
      console.log(true);
      else
      sidebar.removeClass('bot');
      sidebar.addClass('stuck');

      $('.stuck').css(
      'top': (header.outerHeight(true) + 20),
      'left': (content.offset().left + content.width()),
      'right': (container.offset().left + container.width())
      );

      console.log(false);


      else
      console.log('fail');
      sidebar.removeClass('stuck');
      sidebar.removeClass('bot');

      );









      share|improve this question














      When I use the code below, when I scroll the sidebar flashes back and forth. testing found that it is because the winTop >= (contentTop - header.height()) condition fails every other scroll iteration.



      The idea is that there is a sidebar on the page that sticks on scroll until it hits the footer, then it positions absolutely to the bottom of its container until scrolling back up.



      It does everything correctly except that condition fails every other "click" of the scroll wheel, causing the sidebar to flash violently.



      Here is a live example: http://www-icoachfirst-com.sandbox.hs-sites.com/test-lptest-lp



      jquery:



      var $window = $(window),
      header = $('.header'),
      sidebar = $('#sidebar'),
      content = $('#content'),
      container = $('.floattrap'),
      footer = $('.footer_main');

      $(window).on('load scroll resize', function()
      var contentTop = sidebar.offset().top,
      winTop = $(window).scrollTop(),
      footerTop = footer.offset().top;

      console.log(winTop);
      if (winTop >= (contentTop - header.height()))

      if (footerTop <= (winTop + $window.height()))
      sidebar.removeClass('stuck');
      sidebar.addClass('bot');
      console.log(true);
      else
      sidebar.removeClass('bot');
      sidebar.addClass('stuck');

      $('.stuck').css(
      'top': (header.outerHeight(true) + 20),
      'left': (content.offset().left + content.width()),
      'right': (container.offset().left + container.width())
      );

      console.log(false);


      else
      console.log('fail');
      sidebar.removeClass('stuck');
      sidebar.removeClass('bot');

      );






      jquery scrolltop






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 6 at 18:44









      JSumJSum

      11411




      11411






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I had a variable wrong. contentTop was set to the top offset of the sidebar I was trying to float so it was going crazy. I meant to set it to the top offset of the content block on the left for stability.






          share|improve this answer






















            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%2f55030133%2frecursion-in-scroll-triggered-conditionals%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I had a variable wrong. contentTop was set to the top offset of the sidebar I was trying to float so it was going crazy. I meant to set it to the top offset of the content block on the left for stability.






            share|improve this answer



























              0














              I had a variable wrong. contentTop was set to the top offset of the sidebar I was trying to float so it was going crazy. I meant to set it to the top offset of the content block on the left for stability.






              share|improve this answer

























                0












                0








                0







                I had a variable wrong. contentTop was set to the top offset of the sidebar I was trying to float so it was going crazy. I meant to set it to the top offset of the content block on the left for stability.






                share|improve this answer













                I had a variable wrong. contentTop was set to the top offset of the sidebar I was trying to float so it was going crazy. I meant to set it to the top offset of the content block on the left for stability.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 6 at 19:03









                JSumJSum

                11411




                11411





























                    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%2f55030133%2frecursion-in-scroll-triggered-conditionals%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

                    AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                    Алба-Юлія

                    Захаров Федір Захарович