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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:18:26+00:00 2026-05-29T05:18:26+00:00

I have a jQuery Carousel script and I want to modify it’s behavior slightly.

  • 0

I have a jQuery Carousel script and I want to modify it’s behavior slightly. Here is the script and test case in jsfiddle: http://jsfiddle.net/A4vHf/1/ . Below is the JS code.

(function($) {

    $.fn.easyPaginate = function(options){

        var defaults = {                
            step: 4,
            delay: 100,
            numeric: true,
            nextprev: true,
            auto:false,
            pause:4000,
            clickstop:true,
            controls: 'pagination',
            current: 'current' 
        }; 

        var options = $.extend(defaults, options); 
        var step = options.step;
        var lower, upper;
        var children = $(this).children();
        var count = children.length;
        var obj, next, prev;        
        var page = 1;
        var timeout;
        var clicked = false;

        function show(){
            clearTimeout(timeout);
            lower = ((page-1) * step);
            upper = lower+step;
            $(children).each(function(i){
                var child = $(this);
                child.hide();
                if(i>=lower && i<upper){ setTimeout(function(){ child.fadeIn('fast') }, ( i-( Math.floor(i/step) * step) )*options.delay ); }
                if(options.nextprev){
                    if(upper >= count) { next.fadeOut('fast'); } else { next.fadeIn('fast'); };
                    if(lower >= 1) { prev.fadeIn('fast'); } else { prev.fadeOut('fast'); };
                };
            }); 
            $('li','#'+ options.controls).removeClass(options.current);
            $('li[data-index="'+page+'"]','#'+ options.controls).addClass(options.current);

            if(options.auto){
                if(options.clickstop && clicked){}else{ timeout = setTimeout(auto,options.pause); };
            };
        };

        function auto(){
            if(upper <= count){ page++; show(); }           
        };

        this.each(function(){ 

            obj = this;

            if(count>step){

                var pages = Math.floor(count/step);
                if((count/step) > pages) pages++;

                var ol = $('<ol id="'+ options.controls +'"></ol>').insertAfter(obj);

                if(options.nextprev){
                    prev = $('<li class="prev">Previous</li>')
                        .hide()
                        .appendTo(ol)
                        .click(function(){
                            clicked = true;
                            page--;
                            show();
                        });
                };

                if(options.numeric){
                    for(var i=1;i<=pages;i++){
                    $('<li data-index="'+ i +'">'+ i +'</li>')
                        .appendTo(ol)
                        .click(function(){  
                            clicked = true;
                            page = $(this).attr('data-index');
                            show();
                        });                 
                    };              
                };

                if(options.nextprev){
                    next = $('<li class="next">Next</li>')
                        .hide()
                        .appendTo(ol)
                        .click(function(){
                            clicked = true;         
                            page++;
                            show();
                        });
                };

                show();
            };
        }); 

    };  

})(jQuery);

My goal is to make the class="prev" and class="next" buttons always visible. I removed the hide(); methods from the code, but I also need to remove the click event handlers because otherwise I can still click on the buttons even when I’m on the last or first pages accordingly – and that’s here things get messed up. I have to bind and unbind the click events but don’t know how to do it properly. So here is my modified version:

(function($) {

$.fn.easyPaginate = function(options){

    var defaults = {                
        step: 4,
        delay: 100,
        numeric: true,
        nextprev: true,
        auto:false,
        pause:4000,
        clickstop:true,
        controls: 'pagination',
        current: 'current' 
    }; 

    var options = $.extend(defaults, options); 
    var step = options.step;
    var lower, upper;
    var children = $(this).children();
    var count = children.length;
    var obj, next, prev;        
    var page = 1;
    var timeout;
    var clicked = false;

    function show(){
        clearTimeout(timeout);
        lower = ((page-1) * step);
        upper = lower+step;
        $(children).each(function(i){
            var child = $(this);
            child.hide();
            if(i>=lower && i<upper){ setTimeout(function(){ child.fadeIn('fast') }, ( i-( Math.floor(i/step) * step) )*options.delay ); }
            if(options.nextprev){
                if(upper >= count) { next.fadeOut('fast'); } else { next.fadeIn('fast'); };
                if(lower >= 1) { prev.fadeIn('fast'); } else { prev.fadeOut('fast'); };
            };
        }); 
        $('li','#'+ options.controls).removeClass(options.current);
        $('li[data-index="'+page+'"]','#'+ options.controls).addClass(options.current);

        if(options.auto){
            if(options.clickstop && clicked){}else{ timeout = setTimeout(auto,options.pause); };
        };
    };

    function auto(){
        if(upper <= count){ page++; show(); }           
    };

    this.each(function(){ 

        obj = this;

        if(count>step){

            var pages = Math.floor(count/step);
            if((count/step) > pages) pages++;

            var ol = $('<ol id="'+ options.controls +'"></ol>').insertAfter(obj);

            if(options.nextprev){
                prev = $('<li class="prev">Previous</li>')
                    .appendTo(ol)
                    .bind('click', function() {
                        clicked = true;
                        page--;
                        show();
                    });
            };

            if(options.numeric){
                for(var i=1;i<=pages;i++){
                $('<li data-index="'+ i +'">'+ i +'</li>')
                    .appendTo(ol)
                    .click(function(){  
                        clicked = true;
                        page = $(this).attr('data-index');
                        show();
                    });                 
                };              
            };

            if(options.nextprev){
                next = $('<li class="next">Next</li>')
                    .appendTo(ol)
                    .bind('click', function() {
                        clicked = true;         
                        page++;
                        show();
                    });
            };

            show();
        };
    }); 

};  

})(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-29T05:18:26+00:00Added an answer on May 29, 2026 at 5:18 am

    What about just checking inside your event handlers if the user has reached the bounds of the pages?

            if(options.nextprev){
                prev = $('<li class="prev">Previous</li>')
                    .appendTo(ol)
                    .bind('click', function() {
    
                        //check to see if there are any more pages in the negative direction
                        if (page > 0) {
                            clicked = true;
                            page--;
                            show();
                        }
                    });
            }
    
            if(options.nextprev){
                next = $('<li class="next">Next</li>')
                    .appendTo(ol)
                    .bind('click', function() {
    
                        //check to see if there are any pages in the positive direction
                        if ((page + 1) < count) {
                            clicked = true;         
                            page++;
                            show();
                        }
                    });
            }
    

    Update

    If you want the previous and next buttons to never dissapear then you need to remove the code in the show() function that fades the elements in and out. That section of code is this:

            if(options.nextprev){
                if(upper >= count) { next.fadeOut('fast'); } else { next.fadeIn('fast'); };
                if(lower >= 1) { prev.fadeIn('fast'); } else { prev.fadeOut('fast'); };
            };
    

    A simple fix is to just comment this section-out, here is a demo: http://jsfiddle.net/A4vHf/18/

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

Sidebar

Related Questions

i have this script found here http://jsfiddle.net/g4txt/ i am using this carousel http://www.thomaslanciaux.pro/jquery/jquery_carousel.htm the
I currently have a jQuery Slider in progress: http://jsfiddle.net/hQj8a/ $(document).ready(function() { $('body').removeClass('no-js'); $('#my-carousel-2').carousel({ itemsPerPage:
My setup: http://jsfiddle.net/ASa2K/1/ I have a Jquery Infinite Carousel which will have in it
I have a jQuery script that creates a carousel to rotate images left and
I'm using the jquery carousel and I have the image auto rotating here (
I have this jQuery carousel going: http://dougie.thewestharbour.com/wp-content/themes/dougie/slider.html It works pretty well right now but
I'm struggling to find the right terminology here, but if you have jQuery object...
I have built a carousel using the jQuery cycle plugin. I have 4 links
Cheers, I have a strange side effect from a jQuery carousel I am using
Is it possible to use JQuery UI slider with the JQuery Carousel plugin? http://jqueryui.com/demos/slider/

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.