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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:07:50+00:00 2026-06-11T10:07:50+00:00

I am making a website in which I have multiple pages. I want them

  • 0

I am making a website in which I have multiple pages. I want them not be a different webpage but to be a different div on the same page. Then I have two left and right buttons on which it, when a user clicks a particular div, should slide left or right according to the arrow. How can I do this with jQuery, HTML, CSS?

My Divs:

<div id="main-page">    
</div>
<div id="about-us">
</div>
<div id="contact-us">
</div>

The Divs have a particular background-image, and their size is full-screen.

My script:

$("#main-page").click(function() {
    $("#main-page").hide("slide", {direction: "left"}, 1000);
    $("#about-us").show("slide", {direction: "right"}, 1000);
});

As I said, I don’t want to do like that. I want arrows to check what div has the turn to slide left or right.

  • 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-11T10:07:52+00:00Added an answer on June 11, 2026 at 10:07 am

    HTML

    <div id="wrapper">
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
    </div>
    <input type="button" class="next" value="Next">
    <input type="button" class="prev" value="Prev">
    

    CSS

    #wrapper {
        white-space: nowrap;
        width: 1500px
    }
    
    .box {
        width: 200px;
        height: 200px;
        border: thin solid red;
        margin: 0 10px 0 0;
        display: inline-block
    }
    
    ​.prev,
    .next { position: fixed; top: 50% }
    
    .prev { left: 0 }
    .next { right: 0 }
    

    JS

    $(function() {
        // We create an array and populate
        // it with all .box left offsets
        var boxLefts = [];
        $('.box').each(function(i, el) {
            boxLefts.push(this.offsetLeft);
        });
    
        // Now we attach an on click event handler
        // to our prev/next buttons
        $(".prev, .next").click(function(e) {
            var dir = false,
                targetLeft = -1;
    
            // to get the current direction
            // we use the className of the current clicked button
            var target = e.target.className;
    
            // we set the earlier defined direction variable
            // based on the clicked button
            if (target == 'next') {
                dir = 1;
            } else {
                dir = -1;
            }
    
            // when the next-button is clicked
            // we loop through the .box-offsets array
            if (dir) {
                // prevent the default onclick behaviour
                e.preventDefault();
    
                // get the current scroll-offset
                winLeft = window.scrollX;
    
                $.each(boxLefts, function(i, v) {
                    // we check that we are not at the end or beginning
                    // of the viewport. If we are not
                    // we set targetLeft to the current/matching offsets-array item.
                    if ((dir == 1 && winLeft < v && targetLeft < 0) || (dir == -1 && winLeft > v)) {
                        targetLeft = v;
                    }
                });
    
                // if truthy we animate the scrolling to the next/previous box-offset
                if (!targetLeft) {
                    $('html:not(:animated), body:not(:animated)').stop().animate({
                        scrollLeft: targetLeft
                    }, 1000);
                }
            }
    
            // prevent the default onclick behaviour
            return false;
        });
    });
    

    Demo

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

Sidebar

Related Questions

I'making website which is for all desktop/iPad/iPhone. In one page I have header and
I have my first professional assignment of making a website in which a photographer's
I am making a website in ASP.NET and want to be able to have
I have a classifieds website and I am making a mod which will mail
I have a website which I host myself. I do not have a static
i have a website which i want my users to access from their iphones
I'm making a shopping mall website using a Yahoo solution. I have multiple options
I'm making a website which allows people to upload files, html pages, etc... Now
I am making a website for my college in which students will have to
I'm making a website which basically displays a random image but I need a

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.