Remove fixed bar from sidebar

Asked

Viewed 92 times

1

I have the following code:

JAVASCRIPT

//fix lateral filter and gallery on scrolling
    $('.cd-filter-trigger').click(function () {
        (!window.requestAnimationFrame) ? fixGallery() : window.requestAnimationFrame(fixGallery);
    });

    function fixGallery() {
        var offsetTop = $('.cd-main-content').offset().top,
            scrollTop = $(window).scrollTop();
        ( scrollTop >= offsetTop ) ? $('.cd-main-content').addClass('is-fixed') : $('.cd-main-content').removeClass('is-fixed');
    }

This code performs the fixing of a bar on the side (a filter), however, after the user clicks and the bar is fixed, it should continue to fix only in the area ('.cd-main-content'), however, it is fixed on the whole side of the page.... How can I fix this?

  • Hello Hitch, can you post HTML and CSS and if possible simulate the problem in Stackoverflow Code Snippet (preferably) or Jsfiddle? So you help us help you... :)

  • Kadu... The code is: http://codyhouse.co/demo/content-filter/index.html, I need to resolve the above problem in this code...

  • Ali is the code of framework, right? Isn’t that the problem? Do so, open the browser Developer Tools and check if the element with the class .cd-main-content is with position: relative, because from what I saw the .cd-filter uses position: absolute, then he’ll take the reference top: 0 and left: 0 of the next of kin position: relative, if no relative has this property he will refer to body.

  • Hitch, use the edit button of your question, to add/change information, do not duplicate questions.

1 answer

1


Change the function fixGallery for the following code:

function fixGallery() {
   var offsetTop = $('.cd-main-content').offset().top,
   scrollTop = $(window).scrollTop();
   //( scrollTop >= offsetTop ) ? $('.cd-main-content').addClass('is-fixed') : $('.cd-main-content').removeClass('is-fixed');
}
  • Kadu, I don’t want the fix to go away... I just want the filter to stay fixed after the filter is opened. When I use the fixed class on it before the filter opens, it is fixed on the page and goes down next to the scroll. I want the filter button, to stay fixed only when the filter is open, and to stay fixed when the filter goes down, but when it comes out of the filter, it goes back to normal with the absolute position... Got it?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.