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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:04:23+00:00 2026-06-09T13:04:23+00:00

I have a container div with fixed size and overflow: scroll, it’s filled with

  • 0

I have a container div with fixed size and overflow: scroll, it’s filled with smaller divs making a sort of list. here is a fiddle example: http://jsfiddle.net/etYSC/2/

what I want is that the scrolling never cuts a box, making always 3 full boxes showing (in this example), so it will scroll always a fixed number of pixels.

How do I do this?

I’m using jquery library.

Google has been a harsh mistress on this question because of the misleading keywords.

— solution

I was able to refine kiranvj code a bit more and I am very pleased with the final result.

snapping the the previous div:

var scrollTimerHandle = "";
var positionTimerHandle = "";

$("#container").scroll(function() {
    var boxSize = 84;   
    var newScrollPosition = parseInt(this.scrollTop / boxSize) * boxSize,
    _this = this;

    clearInterval(scrollTimerHandle);  
    scrollTimerHandle  = setTimeout(function() {
        positionTimerHandle = setInterval(function(){
          if (_this.scrollTop == newScrollPosition){
             clearInterval(positionTimerHandle);                   
          } else {
             _this.scrollTop--;
          }
        }, 5);         

    }, 600);   
});

http://jsfiddle.net/etYSC/7/

snapping to the closest div

var scrollTimerHandle = "";
var positionTimerHandle = "";

$("#container").scroll(function() {
var boxSize = 84;    
var preScrollPosition = parseInt(this.scrollTop / boxSize) * boxSize;
var newScrollPosition = this.scrollTop - preScrollPosition < boxSize /2 
                             ? preScrollPosition : preScrollPosition + boxSize;
_this = this;

clearInterval(scrollTimerHandle);

    scrollTimerHandle  = setTimeout(function() {
        positionTimerHandle = setInterval(function(){      
          if (_this.scrollTop == newScrollPosition){
            clearInterval(positionTimerHandle);
          } else {
              if (_this.scrollTop > newScrollPosition){
                _this.scrollTop--;
              } else {
                _this.scrollTop++;  
              }          
          }
        }, 5);     

    }, 700);
});

http://jsfiddle.net/etYSC/8/

Thanks for all the help, I was lost on how to aproach this and learned a good deal today.

  • 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-09T13:04:24+00:00Added an answer on June 9, 2026 at 1:04 pm

    Not a perfect solution.

    But something like this should work (NB : need to refine)

    ​$("#container").scroll(function() {
    
       this.scrollTop = parseInt(this.scrollTop / 84) * 84; // 84 = height + top and bottom margin
    
    });​​​
    

    Fiddle here http://jsfiddle.net/R7tAK/1/

    Update

    Some what refined code than the above, without any other plugins or libs. (flicker removed)

    var scrollTimerHandle = "";
    
    $("#container").scroll(function() {
    
    var newScrollPosition = parseInt(this.scrollTop / 84) * 84,
        _this = this;
    
        clearInterval(scrollTimerHandle);
    
    scrollTimerHandle  = setTimeout(function() {
       _this.scrollTop = newScrollPosition ;
    
    }, 1000);
    
    
    });​ 
    

    Play here http://jsfiddle.net/R7tAK/4/

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

Sidebar

Related Questions

I have a div that have a fixed size and overflow:auto. If I drop
Aim The aim is to a have a container DIV with a fixed height
I have a container DIV which contains several block-DIVS. Every block-DIV contains SPAN items
I have a container div with the following CSS: #container { position:relative; overflow:hidden; width:200px;
I have a DIV container with several inner DIVs layed out by floating them
I have a square div of fixed size and wish to place an arbitrary
I want to make a container of fixed size that will inside have an
My aim is to have a <div> with a fixed size (dynamically set through
Possible Duplicate: Auto-size dynamic text to fill fixed size container. Let's say i have
Assume that I have a div having the following styles: #container { position: fixed;

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.