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 7159953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:19:02+00:00 2026-05-28T13:19:02+00:00

I have made a jQuery plugin that works fine when applied to a single

  • 0

I have made a jQuery plugin that works fine when applied to a single element.
When I apply it to another element the previous stops behaving like it should.
This way, only the last element applied is working.
What showld I consider when developing the plugin to create the premises for this to work for all elements?

This is the way I made the plugin:

 (function($) {  

      $.fn.scrollabix = function(params) {

        return this.each(function(){
               // my code
            });           

      };  

 })(jQuery);

This is the entire code:

(function($) {  
        // jQuery plugin definition  
        $.fn.scrollabix = function(params) {

            return this.each(function(){

                // OPTIONS/Config
                    $defaultOptions = 
                                        {
                                            direction: 'vertical'
                                        };
                    $.extend($defaultOptions, params);

                // LOCAL PARAMETERS
                    $self = $(this);
                    $scrolled = $("> div", this);                   

                // GET INFO
                    $selfHeight  = parseInt($self.css("height"));
                    $scrolledHeight = parseInt($('> div', $self).css("height"));

                    $selfWidth  = parseInt($self.css("width"));
                    $scrolledWidth = parseInt($('> div', $self).css("width"));

                    $leftOutside = ($scrolledHeight) - parseInt($selfHeight) /*+ 50*/;  // user for Vertivcal only


                // PLUGIN ACTIONS
                    actions = {
                        continous : 0,
                        slideUp : function(q)
                        {
                            if($leftOutside > 0)
                            {
                                slideBy =(120 * 20) / q;

                                currTop = parseInt($scrolled.css("top"));
                                absCurrTop = Math.abs(currTop);

                                if(absCurrTop + slideBy > ($leftOutside))
                                {
                                    $scrolled.stop().animate({top : '-' + $leftOutside + 'px'}, 250);
                                }
                                else
                                {
                                    if(absCurrTop < ($leftOutside))
                                    {
                                        $scrolled.stop().animate({top : '-=' + slideBy}, 250, 'linear', function(){
                                            if(actions.continous == 1)
                                            {
                                                actions.slideUp(q);
                                            }
                                        });
                                    }
                                }                           
                            }
                        },
                        slideDown : function(q)
                        {
                            if($leftOutside > 0)
                            {
                                slideBy =(120 * 20) / q;

                                currTop = parseInt($scrolled.css("top"));
                                absCurrTop = Math.abs(currTop);

                                if(absCurrTop - slideBy < 0)
                                {
                                    slideBy = absCurrTop;
                                }
                                if(currTop < 0)
                                {
                                    $scrolled.stop().animate({top : '+=' + slideBy}, 250, 'linear', function(){
                                        if(actions.continous == 1)
                                        {
                                            actions.slideDown(q);
                                        }
                                    });
                                }
                            }
                        },
                        slideLeft : function(q)
                        {
                            if($leftOutside > 0)
                            {
                                consolex('slideLeft');
                            }                           
                        },
                        slideRight : function(q)
                        {
                            if($leftOutside > 0)
                            {
                                consolex('slideRight');
                            }
                        }
                    }

                // CREATE INFRASTRUCTURE
                    $self.css({
                        overflow : 'hidden',
                        position : 'relative'
                    });
                    $scrolled.css({
                        position : 'absolute',
                        top : '0px',
                        left : '0px'
                    });

                    if($defaultOptions.direction == 'vertical')
                    {
                        $self.mousemove(function(e){
                            var x = parseInt(e.pageX - this.offsetLeft);
                            var y = parseInt(e.pageY - this.offsetTop);

                            if(y > ($selfHeight - 120) && y < $selfHeight)
                            {
                                actions.continous = 1;
                                actions.slideUp($selfHeight - y);
                            }
                            else if(y < 120 && y >= 1)
                            {
                                actions.continous = 1;
                                actions.slideDown(y);           
                            }
                            else
                            {
                                actions.continous = 0;
                            }
                        }).mouseout(function(){
                            actions.continous = 0;
                        });
                    }
                    else if ($defaultOptions.direction == 'horizontal')
                    {

                        $leftOutside = $scrolledWidth - $selfWidth;                     

                        $self.mousemove(function(e){
                            $scrolledWidth = parseInt($scrolled.css('width'));

                            var x = parseInt(e.pageX - this.offsetLeft);
                            $selfWidth = parseInt($self.css("width"));
                            $leftOutside = ($scrolledWidth) - parseInt($selfWidth);
                            consolex($leftOutside);

                            if(x < 300 && x >= 1)
                            {
                                actions.continous = 1;
                                actions.slideRight(x);                              
                            }
                            else if( x > $selfWidth - 300)
                            {
                                actions.continous = 1;
                                actions.slideLeft(x);                               
                            }

                        }).mouseout(function(){
                            actions.continous = 0;
                        });
                    }
                //return this;
            });           
        };  
    })(jQuery);
  • 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-28T13:19:02+00:00Added an answer on May 28, 2026 at 1:19 pm

    You are doing the right way using this.each() inside the plugin and applying the logic on each element. If you are messing up inside each block then that might create problem.

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

Sidebar

Related Questions

I have made a CSS3 animation plugin for jquery that works perfectly in JS
I have a table that I've made sortable using the jQuery plugin Tablesorter 2.0
I have a div element which is made jquery Resizable. It has alsoResize option
I have started using jQuery and rails. I have made a simple form that
I'm using jQuery and made a plugin for some in house work that basically
Good afternoon people's I have built a jquery plugin that I use on my
I have been working on a jquery plugin that uses a HTML5 audio player
I made my first jQuery plugin attempt, but I have this problem/bug which I
I have menu made with Superfish jquery plugin http://users.tpg.com.au/j_birch/plugins/superfish But i have some problems
I see that per the jQuery plugin template page that jQuery plugins have gone

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.