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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:50:18+00:00 2026-05-31T01:50:18+00:00

I’m trying to make a mini draggable element that will show items in a

  • 0

I’m trying to make a mini draggable element that will show items in a container, that way the user can drag the items to view the other items on the right when when dragging.

This is what it looks like at the moment:

enter image description here

When the user drags it, it should reveal the other boxes on the right (10, 11, 12, 13, etc…) with the white box as the container, but my code seems to make it drag in the reverse direction, for example, if the user drags in right direction, the boxes go left direction and left direction goes the right direction.

When dragging into the left direction:

enter image description here

When dragging into the right direction:

enter image description here

This is my code:

var firstTouch;
$('.scroll-wrapper').bind('touchstart touchmove', function(event)
{
    if(event.type == 'touchstart')
    {
        firstTouch = event.originalEvent.touches[0].pageX;  
    }

    var scrollAmount = firstTouch - event.originalEvent.touches[0].pageX;

    $(this).css('left', scrollAmount);
});

What I would like to also have is to stop the boxes from scrolling when it has reached the end of the container if the box 0 is at the edge of the left then it should not be able to drag into the left direction anymore except to be dragged in the right direction, same goes for the last box should not continue to drag.

How can I accomplish this? I do not want to include any mobile plugins (jQuery, Sencha, etc).

EDIT:

My source:

.scroll-area {
    height: 30px;
    overflow: visible; 
    position: relative; 
    z-index: 1; 
}

.scroll-area .scroll-wrapper {
    height: 30px;
    position: absolute;
    left: 0;
    top: 0; 
}

.scroll-area .scroll-wrapper .item {
    float: left;
    height: 30px;
    width: 30px;
    background-color: #F00;
    margin: 2px;    
}

<div class="scroll-area">
    <div class="scroll-wrapper">
        <div class="item">0</div>
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
        <div class="item">4</div>
        <div class="item">5</div>
        <div class="item">6</div>
        <div class="item">7</div>
        <div class="item">8</div>
        <div class="item">9</div>
        <div class="item">10</div>
        <div class="item">11</div>
        <div class="item">12</div>
        <div class="item">13</div>
        <div class="item">14</div>
        <div class="item">15</div>
        <div class="item">16</div>
        <div class="item">17</div>
        <div class="item">18</div>
        <div class="item">19</div>
        <div class="item">20</div>
        <div class="item">21</div>
        <div class="item">22</div>
        <div class="item">23</div>
        <div class="item">24</div>
        <div class="item">25</div>
    </div>
</div>
  • 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-31T01:50:19+00:00Added an answer on May 31, 2026 at 1:50 am

    Looks like you just have your sign reversed. Then add a check to see if the scroll is over the maximum scroll value (content width – display area width), and set it to maximum if it does. The lower threshold is easier (0).

    Edit: Just realized you probably want to add your current position to your scroll offset. Example edited.

    var firstTouch;
    var drag = 0;
    var startPos = 0;
    
    // Maximum scroll value to (swiping left), minimum is 0
    var maxScroll = $('.scroll-wrapper').outerWidth() - $('.scroll-wrapper').parent().innerWidth();
    
    $('.scroll-area').on('touchstart touchmove', '.scroll-wrapper', function(event) {
        event.preventDefault();
    
        if (event.type == 'touchstart') {
            firstTouch = event.originalEvent.touches[0].pageX;
            startPos = parseInt($(this).css('left'));
            if (isNaN(startPos)) {
                startPos = 0;
            }
        }
    
        // current - first, not the other way around
        // This is negative for swiping left
        var scrollAmount = event.originalEvent.touches[0].pageX - firstTouch;
    
        var offset = startPos + scrollAmount;
    
    
        if (-offset > maxScroll) {
            offset = -maxScroll;
        } else if (offset > 0) {
            offset = 0;
        }
        $(this).css('left', offset);
    
    });
    

    Click version in jQuery: http://jsfiddle.net/Gcgpg/6/

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.