Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 359277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:22:43+00:00 2026-05-12T12:22:43+00:00

I wrote my own function that keeps a sidebar fixed on screen after a

  • 0

I wrote my own function that keeps a sidebar fixed on screen after a certain point of scrolling and then returns it to it’s relative position when scrolled back to the top. If the window is resized to a size smaller then the height of the sidebar, it returns it to its normal relative position as well. Works great!

Problem is when I run another function, namely fancybox(), on the panoramic thumbnail in the body of the page, and try scrolling, my original “scroll-fix” function seems to stop working.

Anyone know why this is?

////////////////////
Demo Page

////////////////////

////////////////////////////////////
“Scroll-Fix” Function

 $(document).ready(function(){

  var element = $("#sidebar");
  var window_height = $(window).height();
  var element_height = element.height();

  $(window).ready(function() { 
    if (window_height > element_height) {
      if (($(document).scrollTop() + element.height()) > ($(document).height() - $("#footer").height() - 9)) {
        element.css("position","absolute");
        element.css("top", "auto");
        element.css("bottom","-60px");
      }
      else if ($(document).scrollTop() > 220) {
        element.css("position","fixed");
        element.css("top","9px");
        element.css("padding-top","0");
        element.css("bottom","auto");
      }
      else {
        element.css("position","relative");
        element.css("top","auto");
        element.css("padding-top","57px");
        element.css("bottom","auto");    
      }
    }
    else {
      element.css("position","relative");
      element.css("top","auto");
      element.css("padding-top","57px");
        element.css("bottom","auto");
    }
  });


  $(window).scroll(function() { 
    if (window_height > element_height) {
      if (($(document).scrollTop() + element.height()) > ($(document).height() - $("#footer").height() - 9)) {
        element.css("position","absolute");
        element.css("top", "auto");
        element.css("bottom","-60px");
      }
      else if ($(document).scrollTop() > 220) {
        element.css("position","fixed");
        element.css("top","9px");
        element.css("padding-top","0");
        element.css("bottom","auto");
      }
      else {
        element.css("position","relative");
        element.css("top","auto");
        element.css("padding-top","57px");
        element.css("bottom","auto");    
      }
    }
    else {
      element.css("position","relative");
      element.css("top","auto");
      element.css("padding-top","57px");
        element.css("bottom","auto");
    }
  });

  $(window).resize(function(){
    window_height = $(window).height();
    if (window_height > element_height) {
      if (($(document).scrollTop() + element.height()) > ($(document).height() - $("#footer").height() - 9)) {
        element.css("position","absolute");
        element.css("top", "auto");
        element.css("bottom","-60px");
      }
      else if ($(document).scrollTop() > 220) {
        element.css("position","fixed");
        element.css("top","9px");
        element.css("padding-top","0");
        element.css("bottom","auto");
      }
      else {
        element.css("position","relative");
        element.css("top","auto");
        element.css("padding-top","57px"); 
        element.css("bottom","auto");     
      }
    }
    else {
      element.css("position","relative");
      element.css("top","auto");
      element.css("padding-top","57px");
        element.css("bottom","auto");
    }
  });

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T12:22:44+00:00Added an answer on May 12, 2026 at 12:22 pm

    first changes for this code to not generate the same problems

    (function($) {
        $.fn.myScrollFix = function(options) {
    
            options = $.extend({
                footer:  "footer",
                pthis: this,
                doc: $(document),
                win: $(window)
            }, options || {});
    
            options.footer = $(options.footer);
            options.accion = function() {
    
                var element = options.pthis,
                    doc_scroll_top = options.doc.scrollTop(),
                    doc_height  = options.doc.height(),
                    window_height = options.win.height(),
                    element_height = options.pthis.height(),
                    footer_height = options.footer.height();
    
                if (window_height > element_height) {
                    if ((doc_scroll_top + element_height) > (doc_height - footer_height - 9)) {
                        element
                            .css("position","absolute")
                            .css("top", "auto")
                            .css("bottom","-60px");
                    }
                    else if (doc_scroll_top > 220) {
                        element
                            .css("position","fixed")
                            .css("top","9px")
                            .css("padding-top","0")
                            .css("bottom","auto");
                    }
                    else {
                        element
                            .css("position","relative")
                            .css("top","auto")
                            .css("padding-top","57px")
                            .css("bottom","auto");    
                    }
                }
                else {
                    element
                        .css("position","relative")
                        .css("top","auto")
                        .css("padding-top","57px")
                        .css("bottom","auto");
                }
            };
    
            $(window).bind("scroll", options.accion);
            $(window).bind("resize", options.accion);
    
            options.accion();
        };
    })(jQuery);
    $(document).ready(function(){
        $("#sidebar").myScrollFix();
    });
    

    then you can modify these lines in FancyBox

    line 432

    $(window).unbind("resize scroll", $.fn.fancybox.scrollBox);
    

    line 439

    $(window).unbind("resize scroll", $.fn.fancybox.scrollBox);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php function I wrote that will take a text file and
I wrote my own php captcha script, with a jpeg header, so that I
I have an application that allows users to write their own code in a
I wrote a windows service using VB that read some legacy data from Visual
I wrote myself a little downloading application so that I could easily grab a
Is there a library function that performs binary search on a list/tuple and return
I've wrote my own PHP MVC however i'm struggling to distinguish between the model
Before I write my own I will ask all y'all. I'm looking for a
I would like to write my own OS, and would like to temporarily jump
I'd like to write my own script in C# to test my own dictionary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.