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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:45:53+00:00 2026-06-18T11:45:53+00:00

I want to make a very simple function in my jQuery script. When the

  • 0

I want to make a very simple function in my jQuery script. When the finger/cursor touches/clicks on the screen, I want the pages to slide horizontally following the movements of the finger/cursor. I know there is a lot of plugins created by so many people, but I really don’t need everybody else’s solutions. The image is a visual view of how my HTML looks like. it is really simple.

The jQuery sciprt is obviously not correct, but I hope it would give you an idea about the simple function I need. I don’t extra classes or fade-functions or anything.

$(document).live('touchmove' or 'mousemove', function() {
    $('div[class=page_*], div[class=page_^]').[follow movements horizontally, and auto align to nearest edge when let go.];
});

Also I want to be able to do the same with one big div, so probably the width-variable of the element moving should be equal to $(window).width();. Actually I think that would be the best idea. I can always put more content inside the big div and make it larger, so keep it with that. It should be more simple to do and to focus on one element only.

Figure

  • 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-18T11:45:54+00:00Added an answer on June 18, 2026 at 11:45 am

    So, here is my solution. I’ve made some changes so that now you can have more than 3 pages.
    Also, I’ve defined a variable named threshold set to the half of a page. If you want to have a threshold bigger or smaller than the hakf of the page you will have to make some more changes.

    HTML CODE:

    <div class="container">
        <div class="wrap">
            <div class="page page1"></div>
            <div class="page page2"></div>
            <div class="page page3"></div>
            <div class="page page4"></div>
        </div>
    </div>
    

    CSS CODE:

    .container, .page, .wrap {
        width: 300px;
        height: 400px;
    }
    .container {
        background: #efefef;
        box-shadow: 0px 0px 10px black;
        overflow: hidden;
        position: relative;
        margin: 5px auto;
    }
    .wrap {
        width: 1200px;
        position: absolute;
        top: 0;
        left: 0;
    }
    .page {
        float: left;
        display: block;
        -moz-user-select: none;
        -khtml-user-select: none;
        -webkit-user-select: none;
        -o-user-select: none;
    }
    .page1 {
        background: yellow;
    }
    .page2 {
        background: green;
    } 
    .page3 {
        background: blue;
    }
    .page4 {
        background: red;
    }
    

    As for the CSS code keep in mind that if you want to change the page size you will also have to change the container and wrap size.

    JS CODE:

    var mouseDown = false, right;
    var xi, xf, leftX = 0;
    var nPages = $(".page").size();
    var pageSize = $(".page").width();
    var threshold = pageSize/2;
    var currentPage = 0;
    
    $(".container").on("mousedown", function (e) {
        mouseDown = true;
        xi = e.pageX;
    });
    
    $(".container").on("mouseup", function (e) {
        if (mouseDown) {
            mouseDown = false;
            xf = e.pageX;
            leftX = parseInt($(".wrap").css("left").split("px")[0]);
            if ((e.pageX - xi) < -threshold || (e.pageX - xi) > threshold) {
                setFocusedPage();
            } else {
                restore();
            }
        }
    });
    
    $(".container").on("mouseleave", function (e) {
        if (mouseDown) {
            mouseDown = false;
            xf = e.pageX;
            leftX = parseInt($(".wrap").css("left").split("px")[0]);
            if ((e.pageX - xi) < -threshold || (e.pageX - xi) > threshold) {
                setFocusedPage();
            } else {
                restore();
            }
        }
    });
    
    $(".container").on("mousemove", function (e) {
        if (mouseDown) {
            $(".wrap").css({
                "left": (leftX + (e.pageX - xi))
            });
            right = ((e.pageX - xi) < 0) ? true : false;
        }
    });
    
    function restore() {
        $(".wrap").stop().animate({
            "left": -(currentPage * pageSize)
        }, 200, function () {
            leftX = parseInt($(".wrap").css("left").split("px")[0]);
        });
    }
    
    function setFocusedPage() {
        if (leftX >= (-threshold)) { // First Page
            currentPage = 0;
        } else if (leftX < (-threshold) && leftX >= (-(nPages + 1) * threshold)) { // Second to N-1 Page
            (right) ? currentPage++ : currentPage--;
        } else if (leftX < -((nPages + 1) * threshold)) { // Third Page
            currentPage = nPages - 1;
        }
        $(".wrap").stop().animate({
            "left": -(currentPage * pageSize)
        }, 200, function () {
            leftX = parseInt($(".wrap").css("left").split("px")[0]);
        });
    }
    

    Remember here that if you want a different threshold you will have to make some changes especially in the setFocusedPage() function.

    Here is my last DEMO

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

Sidebar

Related Questions

i want to make a simple jquery slider, i dont know jquery very well,
I'm creating a very simple django upload application but I want to make it
I am trying to make a very very simple script that checks to see
I want to make an very simple chatting page no login required no sql
Hey i'm trying to make a very simple GUI using SFML, and i want
I have a very basic function which I am using jQuery to slide some
I want to make a simple HTTPRequest to a php script and I have
I want to make a very simple task in objective-c under IOS5 : convert
I am working on a very simple game in Flash. I want to make
I want make datetimepicker in my project. Using jquery how it is possible? I

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.