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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:27:00+00:00 2026-05-24T12:27:00+00:00

I am creating a next/prev navigation from scratch and would like the click of

  • 0

I am creating a next/prev navigation from scratch and would like the click of the “next” button to increase (animate) margin left by X on each click until the end is reached (in this case -320px), similar method for the back button. I am probably being uber dense – but my javascript is below:

 function myFunction() {

    "use strict";

    if (jQuery) {
        var $next = $(".next"),
            $back = $(".back"),
            $box = $(".box"),
            regWidth = $box.width(),
            $contain = $(".contain"),
            len = 0,
            combinedWidth = 0,
            len = $box.length;

        while (len--) {

            combinedWidth = combinedWidth + $($box[len]).width();

        }


        $contain.width(combinedWidth);


        $next.bind('click', function (e) {

            e.preventDefault();


            var $this = $(this),
                $tWidth = $this.width();



            $contain.animate({

                marginLeft: "+=" + (-regWidth) + "px"

            });

        });

        //click event for back  
        $back.click(function (e) {
            e.preventDefault();

            var $this = $(this),
                $tWidth = $this.width();
            $contain.animate({

                marginLeft: "+=" + (regWidth) + "px"

            });


        });





    }
};

$(function () {

    myFunction();
});

The CSS is as follows:

#wrap {
    width:320px;
    margin:0 auto;
    overflow:hidden;

}
.contain {

    float:left;
    background:#e9e9e9;
    height:480px;

}

.box
{
    min-height:75px;
}

Any help would be much appreciated!!

  • 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-24T12:27:01+00:00Added an answer on May 24, 2026 at 12:27 pm

    You use it like this:

    $element.animate({marginLeft: "+=Npx"});
    

    Where N is the number of pixels. Example

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

Sidebar

Related Questions

I know that when creating buttons, like next and previous, that the code can
I am creating a mail like scenario where a user has a next and
Problem: I am creating an album.So on every press of time NEXT button I
I'm creating random time in random date in next month like this var time
Hi I am creating a simple slide show with next / prev buttons. When
I've got the following in my .css file creating a little image next to
Creating a patch is very easy in SubVersion, With Tortoise, you right-click and select
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
I'm creating a next/previous function for my repeater using pageddatasource. I added the link

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.