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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:46:30+00:00 2026-06-17T08:46:30+00:00

I have the following jquery file… how can I directly access $navPrev and $navNext

  • 0

I have the following jquery file…
how can I directly access $navPrev and $navNext functions directly in my inline script or on any event I want. for example:

    $("a").swipe( {
    //Generic swipe handler for all directions
        swipe:function(event, direction, distance, duration, fingerCount) {
             // My code here to move next or previous based on swipe action.
         ); 
             },
});

I am basically tying to add jquery swipe feature to scroll the the slider. and for that I need to be able to access the next and previous functions directly.

(function( $, undefined ) {

 // Gallery object.

$.Gallery               = function( options, element ) {

    this.$el    = $( element );
    this._init( options );

};

$.Gallery.defaults      = {
    current     : 0,    // index of current item
    autoplay    : false,// slideshow on / off
    interval    : 2000  // time between transitions
};

$.Gallery.prototype     = {
    _init               : function( options ) {

        this.options        = $.extend( true, {}, $.Gallery.defaults, options );

        // support for 3d / 2d transforms and transitions
        this.support3d      = Modernizr.csstransforms3d;
        this.support2d      = Modernizr.csstransforms;
        this.supportTrans   = Modernizr.csstransitions;

        this.$wrapper       = this.$el.find('.dg-wrapper');

        this.$items         = this.$wrapper.children();
        this.itemsCount     = this.$items.length;

        this.$nav           = this.$el.find('nav');
        this.$navPrev       = this.$nav.find('.dg-prev');
        this.$navNext       = this.$nav.find('.dg-next');

        // minimum of 3 items
        if( this.itemsCount < 3 ) {

            this.$nav.remove();
            return false;

        }   

        this.current        = this.options.current;

        this.isAnim         = false;

        this.$items.css({
            'opacity'   : 0,
            'visibility': 'hidden'
        });

        this._validate();

        this._layout();

        // load the events
        this._loadEvents();

        // slideshow
        if( this.options.autoplay ) {

            this._startSlideshow();

        }

    },
    _validate           : function() {

        if( this.options.current < 0 || this.options.current > this.itemsCount - 1 ) {

            this.current = 0;

        }   

    },
    _layout             : function() {

        // current, left and right items
        this._setItems();

        // current item is not changed
        // left and right one are rotated and translated
        var leftCSS, rightCSS, currentCSS;

        if( this.support3d && this.supportTrans ) {

            leftCSS     = {
                '-webkit-transform' : 'translateX(-350px) translateZ(-200px) rotateY(45deg)',
                '-moz-transform'    : 'translateX(-350px) translateZ(-200px) rotateY(45deg)',
                '-o-transform'      : 'translateX(-350px) translateZ(-200px) rotateY(45deg)',
                '-ms-transform'     : 'translateX(-350px) translateZ(-200px) rotateY(45deg)',
                'transform'         : 'translateX(-350px) translateZ(-200px) rotateY(45deg)'
            };

            rightCSS    = {
                '-webkit-transform' : 'translateX(350px) translateZ(-200px) rotateY(-45deg)',
                '-moz-transform'    : 'translateX(350px) translateZ(-200px) rotateY(-45deg)',
                '-o-transform'      : 'translateX(350px) translateZ(-200px) rotateY(-45deg)',
                '-ms-transform'     : 'translateX(350px) translateZ(-200px) rotateY(-45deg)',
                'transform'         : 'translateX(350px) translateZ(-200px) rotateY(-45deg)'
            };

            leftCSS.opacity     = 1;
            leftCSS.visibility  = 'visible';
            rightCSS.opacity    = 1;
            rightCSS.visibility = 'visible';

        }
        else if( this.support2d && this.supportTrans ) {

            leftCSS     = {
                '-webkit-transform' : 'translate(-350px) scale(0.8)',
                '-moz-transform'    : 'translate(-350px) scale(0.8)',
                '-o-transform'      : 'translate(-350px) scale(0.8)',
                '-ms-transform'     : 'translate(-350px) scale(0.8)',
                'transform'         : 'translate(-350px) scale(0.8)'
            };

            rightCSS    = {
                '-webkit-transform' : 'translate(350px) scale(0.8)',
                '-moz-transform'    : 'translate(350px) scale(0.8)',
                '-o-transform'      : 'translate(350px) scale(0.8)',
                '-ms-transform'     : 'translate(350px) scale(0.8)',
                'transform'         : 'translate(350px) scale(0.8)'
            };

            currentCSS  = {
                'z-index'           : 999
            };

            leftCSS.opacity     = 1;
            leftCSS.visibility  = 'visible';
            rightCSS.opacity    = 1;
            rightCSS.visibility = 'visible';

        }

        this.$leftItm.css( leftCSS || {} );
        this.$rightItm.css( rightCSS || {} );

        this.$currentItm.css( currentCSS || {} ).css({
            'opacity'   : 1,
            'visibility': 'visible'
        }).addClass('dg-center');

    },
    _setItems           : function() {

        this.$items.removeClass('dg-center');

        this.$currentItm    = this.$items.eq( this.current );
        this.$leftItm       = ( this.current === 0 ) ? this.$items.eq( this.itemsCount - 1 ) : this.$items.eq( this.current - 1 );
        this.$rightItm      = ( this.current === this.itemsCount - 1 ) ? this.$items.eq( 0 ) : this.$items.eq( this.current + 1 );

        if( !this.support3d && this.support2d && this.supportTrans ) {

            this.$items.css( 'z-index', 1 );
            this.$currentItm.css( 'z-index', 999 );

        }

        // next & previous items
        if( this.itemsCount > 3 ) {

            // next item
            this.$nextItm       = ( this.$rightItm.index() === this.itemsCount - 1 ) ? this.$items.eq( 0 ) : this.$rightItm.next();
            this.$nextItm.css( this._getCoordinates('outright') );

            // previous item
            this.$prevItm       = ( this.$leftItm.index() === 0 ) ? this.$items.eq( this.itemsCount - 1 ) : this.$leftItm.prev();
            this.$prevItm.css( this._getCoordinates('outleft') );

        }

    },
    _loadEvents         : function() {

        var _self   = this;

        this.$navPrev.on( 'click.gallery', function( event ) {

            if( _self.options.autoplay ) {

                clearTimeout( _self.slideshow );
                _self.options.autoplay  = false;

            }

            _self._navigate('prev');

            return false;

        });

        this.$navNext.on( 'click.gallery', function( event ) {

            if( _self.options.autoplay ) {

                clearTimeout( _self.slideshow );
                _self.options.autoplay  = false;

            }

            _self._navigate('next');
            return false;

        });

        this.$wrapper.on( 'webkitTransitionEnd.gallery transitionend.gallery OTransitionEnd.gallery', function( event ) {

            _self.$currentItm.addClass('dg-center');
            _self.$items.removeClass('dg-transition');
            _self.isAnim    = false;

        });

    },
    _getCoordinates     : function( position ) {

        if( this.support3d && this.supportTrans ) {

            switch( position ) {
                case 'outleft':
                    return {
                        '-webkit-transform' : 'translateX(-450px) translateZ(-300px) rotateY(45deg)',
                        '-moz-transform'    : 'translateX(-450px) translateZ(-300px) rotateY(45deg)',
                        '-o-transform'      : 'translateX(-450px) translateZ(-300px) rotateY(45deg)',
                        '-ms-transform'     : 'translateX(-450px) translateZ(-300px) rotateY(45deg)',
                        'transform'         : 'translateX(-450px) translateZ(-300px) rotateY(45deg)',
                        'opacity'           : 0,
                        'visibility'        : 'hidden'
                    };
                    break;
                case 'outright':
                    return {
                        '-webkit-transform' : 'translateX(450px) translateZ(-300px) rotateY(-45deg)',
                        '-moz-transform'    : 'translateX(450px) translateZ(-300px) rotateY(-45deg)',
                        '-o-transform'      : 'translateX(450px) translateZ(-300px) rotateY(-45deg)',
                        '-ms-transform'     : 'translateX(450px) translateZ(-300px) rotateY(-45deg)',
                        'transform'         : 'translateX(450px) translateZ(-300px) rotateY(-45deg)',
                        'opacity'           : 0,
                        'visibility'        : 'hidden'
                    };
                    break;
                case 'left':
                    return {
                        '-webkit-transform' : 'translateX(-350px) translateZ(-200px) rotateY(45deg)',
                        '-moz-transform'    : 'translateX(-350px) translateZ(-200px) rotateY(45deg)',
                        '-o-transform'      : 'translateX(-350px) translateZ(-200px) rotateY(45deg)',
                        '-ms-transform'     : 'translateX(-350px) translateZ(-200px) rotateY(45deg)',
                        'transform'         : 'translateX(-350px) translateZ(-200px) rotateY(45deg)',
                        'opacity'           : 1,
                        'visibility'        : 'visible'
                    };
                    break;
                case 'right':
                    return {
                        '-webkit-transform' : 'translateX(350px) translateZ(-200px) rotateY(-45deg)',
                        '-moz-transform'    : 'translateX(350px) translateZ(-200px) rotateY(-45deg)',
                        '-o-transform'      : 'translateX(350px) translateZ(-200px) rotateY(-45deg)',
                        '-ms-transform'     : 'translateX(350px) translateZ(-200px) rotateY(-45deg)',
                        'transform'         : 'translateX(350px) translateZ(-200px) rotateY(-45deg)',
                        'opacity'           : 1,
                        'visibility'        : 'visible'
                    };
                    break;
                case 'center':
                    return {
                        '-webkit-transform' : 'translateX(0px) translateZ(0px) rotateY(0deg)',
                        '-moz-transform'    : 'translateX(0px) translateZ(0px) rotateY(0deg)',
                        '-o-transform'      : 'translateX(0px) translateZ(0px) rotateY(0deg)',
                        '-ms-transform'     : 'translateX(0px) translateZ(0px) rotateY(0deg)',
                        'transform'         : 'translateX(0px) translateZ(0px) rotateY(0deg)',
                        'opacity'           : 1,
                        'visibility'        : 'visible'
                    };
                    break;
            };

        }
        else if( this.support2d && this.supportTrans ) {

            switch( position ) {
                case 'outleft':
                    return {
                        '-webkit-transform' : 'translate(-450px) scale(0.7)',
                        '-moz-transform'    : 'translate(-450px) scale(0.7)',
                        '-o-transform'      : 'translate(-450px) scale(0.7)',
                        '-ms-transform'     : 'translate(-450px) scale(0.7)',
                        'transform'         : 'translate(-450px) scale(0.7)',
                        'opacity'           : 0,
                        'visibility'        : 'hidden'
                    };
                    break;
                case 'outright':
                    return {
                        '-webkit-transform' : 'translate(450px) scale(0.7)',
                        '-moz-transform'    : 'translate(450px) scale(0.7)',
                        '-o-transform'      : 'translate(450px) scale(0.7)',
                        '-ms-transform'     : 'translate(450px) scale(0.7)',
                        'transform'         : 'translate(450px) scale(0.7)',
                        'opacity'           : 0,
                        'visibility'        : 'hidden'
                    };
                    break;
                case 'left':
                    return {
                        '-webkit-transform' : 'translate(-350px) scale(0.8)',
                        '-moz-transform'    : 'translate(-350px) scale(0.8)',
                        '-o-transform'      : 'translate(-350px) scale(0.8)',
                        '-ms-transform'     : 'translate(-350px) scale(0.8)',
                        'transform'         : 'translate(-350px) scale(0.8)',
                        'opacity'           : 1,
                        'visibility'        : 'visible'
                    };
                    break;
                case 'right':
                    return {
                        '-webkit-transform' : 'translate(350px) scale(0.8)',
                        '-moz-transform'    : 'translate(350px) scale(0.8)',
                        '-o-transform'      : 'translate(350px) scale(0.8)',
                        '-ms-transform'     : 'translate(350px) scale(0.8)',
                        'transform'         : 'translate(350px) scale(0.8)',
                        'opacity'           : 1,
                        'visibility'        : 'visible'
                    };
                    break;
                case 'center':
                    return {
                        '-webkit-transform' : 'translate(0px) scale(1)',
                        '-moz-transform'    : 'translate(0px) scale(1)',
                        '-o-transform'      : 'translate(0px) scale(1)',
                        '-ms-transform'     : 'translate(0px) scale(1)',
                        'transform'         : 'translate(0px) scale(1)',
                        'opacity'           : 1,
                        'visibility'        : 'visible'
                    };
                    break;
            };

        }
        else {

            switch( position ) {
                case 'outleft'  : 
                case 'outright' : 
                case 'left'     : 
                case 'right'    :
                    return {
                        'opacity'           : 0,
                        'visibility'        : 'hidden'
                    };
                    break;
                case 'center'   :
                    return {
                        'opacity'           : 1,
                        'visibility'        : 'visible'
                    };
                    break;
            };

        }

    },
    _navigate           : function( dir ) {

        if( this.supportTrans && this.isAnim )
            return false;

        this.isAnim = true;

        switch( dir ) {

            case 'next' :

                this.current    = this.$rightItm.index();

                // current item moves left
                this.$currentItm.addClass('dg-transition').css( this._getCoordinates('left') );

                // right item moves to the center
                this.$rightItm.addClass('dg-transition').css( this._getCoordinates('center') ); 

                // next item moves to the right
                if( this.$nextItm ) {

                    // left item moves out
                    this.$leftItm.addClass('dg-transition').css( this._getCoordinates('outleft') );

                    this.$nextItm.addClass('dg-transition').css( this._getCoordinates('right') );

                }
                else {

                    // left item moves right
                    this.$leftItm.addClass('dg-transition').css( this._getCoordinates('right') );

                }
                break;

            case 'prev' :

                this.current    = this.$leftItm.index();

                // current item moves right
                this.$currentItm.addClass('dg-transition').css( this._getCoordinates('right') );

                // left item moves to the center
                this.$leftItm.addClass('dg-transition').css( this._getCoordinates('center') );

                // prev item moves to the left
                if( this.$prevItm ) {

                    // right item moves out
                    this.$rightItm.addClass('dg-transition').css( this._getCoordinates('outright') );

                    this.$prevItm.addClass('dg-transition').css( this._getCoordinates('left') );

                }
                else {

                    // right item moves left
                    this.$rightItm.addClass('dg-transition').css( this._getCoordinates('left') );

                }
                break;  

        };

        this._setItems();

        if( !this.supportTrans )
            this.$currentItm.addClass('dg-center');

    },
    _startSlideshow     : function() {

        var _self   = this;

        this.slideshow  = setTimeout( function() {

            _self._navigate( 'next' );

            if( _self.options.autoplay ) {

                _self._startSlideshow();

            }

        }, this.options.interval );

    },
    destroy             : function() {

        this.$navPrev.off('.gallery');
        this.$navNext.off('.gallery');
        this.$wrapper.off('.gallery');

    }
};

var logError            = function( message ) {
    if ( this.console ) {
        console.error( message );
    }
};

$.fn.gallery            = function( options ) {

    if ( typeof options === 'string' ) {

        var args = Array.prototype.slice.call( arguments, 1 );

        this.each(function() {

            var instance = $.data( this, 'gallery' );

            if ( !instance ) {
                logError( "cannot call methods on gallery prior to initialization; " +
                "attempted to call method '" + options + "'" );
                return;
            }

            if ( !$.isFunction( instance[options] ) || options.charAt(0) === "_" ) {
                logError( "no such method '" + options + "' for gallery instance" );
                return;
            }

            instance[ options ].apply( instance, args );

        });

    } 
    else {

        this.each(function() {

            var instance = $.data( this, 'gallery' );
            if ( !instance ) {
                $.data( this, 'gallery', new $.Gallery( options, this ) );
            }
        });

    }

    return this;

};

})( jQuery );

This is my HTML code:

<div class="container">
        <!-- Codrops top bar -->
            <!--/ Codrops top bar -->
  <section id="dg-container" class="dg-container">
    <div class="dg-wrapper">

      <a href="#"><img src="album1.jpg" alt="image05"></a>
      <a href="#"><img src="album2.jpg" alt="image06"></a>
      <a href="#"><img src="album3.jpg" alt="image07"></a>

    </div>
                <nav>   
                    <span class="dg-prev">&lt;</span>
                    <span class="dg-next">&gt;</span>
    </nav>
  </section>
</div>

EDIT:
Here is how the slider is being called from html page

<script type="text/javascript">
            $(function() {
                $me=$('#dg-container').gallery({
                    autoplay    :   true
                });
//              console.log($me);

            });
        </script>
  • 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-17T08:46:30+00:00Added an answer on June 17, 2026 at 8:46 am

    First off, $navNext and $navPrev are not functions, they are just span elements.

    <span class="dg-prev">&lt;</span>
    <span class="dg-next">&gt;</span>
    

    You can use this

    $(".dg-prev")
    $(".dg-next")
    

    to access these elements directly.

    So, in your swipe code, call like this:

    $(".dg-prev").click();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running rails 3.1 and have the following jquery script in a file
Im including the popular file jquery.form.js. I have the following: var options = {
I have the following file structure: |- index.html vendor |- jquery.min.js (some libraries) js
I have the following jquery script: $(function(){ $('#top-menu').on('click', 'a.change-menu', function(e){ e.preventDefault() $(#menu-change-div).load($(this).attr(href)); }); });
I have the following jQuery and the file set-rank.php just updates a database and
I'm following the tutorial here: http://www.jotorres.com/2012/01/using-jquery-and-ajax-with-codeigniter/ For my view, I have: <script type=text/javascript src=<?php
I have the following jQuery ajax request in a .js file: $.ajax({ type: GET,
I have the following html + jquery: <body> <head> <script type=text/javascript src=jquery.js></script> <script> $(window).load(function()
In my .erb file, I have the following jQuery call: $.get(url, { point: pointValue,
I have the following jQuery code in my PHP file (edited Jan 19 2010

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.