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

  • SEARCH
  • Home
  • 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 7859205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:49:09+00:00 2026-06-02T21:49:09+00:00

I’ve never needed to ‘bind’ or ‘unbind’ anything before so I’m getting confused because

  • 0

I’ve never needed to ‘bind’ or ‘unbind’ anything before so I’m getting confused because I can’t find an example that directly relates to what I want to do.

There is a plugin that scrolls a div when you get to a certain point at a page here – you’ve all seen this kind of thing, right?

But I only want the plugin to fire when the window is a certain width, and then ‘unfire’ / unbind if the window is below that width again e.g….

(by the way #contact-form is the container I’m scrolling which contains, you guessed it, a contact form)

function contactForm() {
    windowWidth = $(window).width();
    if (windowWidth >= 1024) {
        jQuery('#contact-form').containedStickyScroll();
    } else {
        jQuery('#contact-form').unbind(); // I don't want the plugin to fire
    }
};    


// Standard stuff...

$(document).ready(function() {
    contactForm();
});

$(window).resize(function() {   
    contactForm();
});

This contained sticky scroll function looks like this:

  $.fn.containedStickyScroll = function( options ) {

    var defaults = {  
        oSelector : this.selector,
        unstick : true,
        easing: 'linear',
        duration: 500,
        queue: false,
        closeChar: '^',
        closeTop: 0,
        closeRight: 0  
    }  

    var options =  $.extend(defaults, options);

    if(options.unstick == true){  
        this.css('position','relative');
        this.append('<a class="scrollFixIt">' + options.closeChar + '</a>');
        jQuery(options.oSelector + ' .scrollFixIt').css('position','absolute');
        jQuery(options.oSelector + ' .scrollFixIt').css('top',options.closeTop + 'px');
        jQuery(options.oSelector + ' .scrollFixIt').css('right',options.closeTop + 'px');
        jQuery(options.oSelector + ' .scrollFixIt').css('cursor','pointer');
        jQuery(options.oSelector + ' .scrollFixIt').click(function() {
            getObject = options.oSelector;
            jQuery(getObject).animate({ top: "0px" },
                { queue: options.queue, easing: options.easing, duration: options.duration });
            jQuery(window).unbind();
            jQuery('.scrollFixIt').remove();
        });
    } 
    jQuery(window).scroll(function() {
        getObject = options.oSelector;
        if(jQuery(window).scrollTop() > (jQuery(getObject).parent().offset().top) &&
           (jQuery(getObject).parent().height() + jQuery(getObject).parent().position().top - 30) > (jQuery(window).scrollTop() + jQuery(getObject).height())){
            jQuery(getObject).animate({ top: (jQuery(window).scrollTop() - jQuery(getObject).parent().offset().top) + "px" }, 
            { queue: options.queue, easing: options.easing, duration: options.duration });
        }
        else if(jQuery(window).scrollTop() < (jQuery(getObject).parent().offset().top)){
            jQuery(getObject).animate({ top: "0px" },
            { queue: options.queue, easing: options.easing, duration: options.duration });
        }
    });

};

  • 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-06-02T21:49:11+00:00Added an answer on June 2, 2026 at 9:49 pm

    The plugin containedStickyScroll is not written very well, because it has no remove handler.

    That leaves you with 3 options:

    1. Fork the plugin.

      $.fn.containedStickyScroll = function( options ) {
      
         return this.each(function() {
      
         var self = this;
      
         function remove() {
              getObject = options.oSelector;
              jQuery(getObject).animate({ top: "0px" }, { queue: options.queue, easing: options.easing, duration: options.duration });
              jQuery(window).unbind("scroll", $self.data("containedStickyScroll").scrollHandler);
              jQuery('.scrollFixIt').remove();
      
              $(self).data("containedStickyScroll", false);
         }
      
          if (options == "remove") {
              remove();
              return;
          }
      
          // Make sure that this is only done once.
          if (this.data("containedStickyScroll"))
              return;
      
          var defaults = {  
              oSelector : this.selector,
              unstick : true,
              easing: 'linear',
              duration: 500,
              queue: false,
              closeChar: '^',
              closeTop: 0,
              closeRight: 0  
          }  
      
          var options =  $.extend(defaults, options);
      
          if(options.unstick == true){  
              $(this).css('position','relative');
              $(this).append('<a class="scrollFixIt">' + options.closeChar + '</a>');
              jQuery(options.oSelector + ' .scrollFixIt').css('position','absolute');
              jQuery(options.oSelector + ' .scrollFixIt').css('top',options.closeTop + 'px');
              jQuery(options.oSelector + ' .scrollFixIt').css('right',options.closeTop + 'px');
              jQuery(options.oSelector + ' .scrollFixIt').css('cursor','pointer');
              jQuery(options.oSelector + ' .scrollFixIt').click(remove);
          } 
      
          options.scrollHandler = function () {
              getObject = options.oSelector;
              if(jQuery(window).scrollTop() > (jQuery(getObject).parent().offset().top) &&
                 (jQuery(getObject).parent().height() + jQuery(getObject).parent().position().top - 30) > (jQuery(window).scrollTop() + jQuery(getObject).height())){
                  jQuery(getObject).animate({ top: (jQuery(window).scrollTop() - jQuery(getObject).parent().offset().top) + "px" }, 
                  { queue: options.queue, easing: options.easing, duration: options.duration });
              }
              else if(jQuery(window).scrollTop() < (jQuery(getObject).parent().offset().top)){
                  jQuery(getObject).animate({ top: "0px" },
                  { queue: options.queue, easing: options.easing, duration: options.duration });
              }
          };
      
          jQuery(window).scroll(options.scrollHandler);
      
          $(this).data("containedStickyScroll", options);
      };};
      

      Now you can do this:

      (function($) {
      
          function contactForm() {
              windowWidth = $(window).width();
              if (windowWidth >= 1024)
                  $('#contact-form').containedStickyScroll();
              else
                  $('#contact-form').containedStickyScroll("remove");
          };    
      
          // Standard stuff...
      
          $(document).ready(contactForm);
      
          $(window).resize(contactForm);
      
      })(jQuery);
      

      I have also removed a terrible practice of unbinding all event handlers from the window object, which is even worse than option 2.

    2. Workaround the problem by removing all event handlers with unbind (including those that are not created by that plugin).

      Not really an option, because the scroll event handler is on the window object and it is very likely that other plugins etc may use the same event handler.

      $(window).unbind("scroll");
      
    3. Reset the entire element on the DOM.

      (function() {
      
          var hasContactForm = false,
              $contactForm = $("#contact-form").clone();
      
          function contactForm() {
              windowWidth = $(window).width();
              if (!hasContactForm && windowWidth >= 1024) {
                  hasContactForm = true;
                  jQuery('#contact-form').containedStickyScroll();
              } else if (hasContactForm && windowWidth < 1024)
                  hasContactForm = false;
                  $('#contact-form').replaceWith($contactForm);
              }
          };    
      
          // Standard stuff...
      
          $(document).ready(contactForm);
      
          $(window).resize(contactForm);
      
      })();
      

      This may not be a viable solution either because it will also reset any of the users input. However you can add extra logic to carry the user input into the restored contact form.

    Considering the many downsides of each option, I would strongly suggest to either find a better plugin, or write your own. Otherwise option 1 is probably the best (if it works).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
Does anyone know how can I replace this 2 symbol below from the string

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.