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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:58:02+00:00 2026-06-04T06:58:02+00:00

The way this function will work: 1) The user clicks the button with ID

  • 0

The way this function will work:

1) The user clicks the button with ID “surf” and the animation begins

2) The function finds the first instance of div with class “threadboard,” pauses there for 1.5 seconds, then smoothly scrolls down to the next instance of a div with class “threadboard,” pauses there for 1.5s and then scrolls smoothly to the next, and so on

3) The function should do this through all the instances of divs with class “threadboard,” and then end

I’m trying to use jQuery with the methods scrollTop(), each(), animate() and setTimeout() so far with mixed success. Here’s what I have so far (EDIT: to include working but imperfect code):

var currentIndex = 0;
var numDivs = 18;

$(window).load(function() {
    $('#surf').click(
        function(){start();}
    );
});

function start() {
//if (numDivs > 0) {
    var winY = window.screenY;
            $("body").animate({ scrollTop: 225 * currentIndex}, 1100);
    //
    currentIndex = (currentIndex + 1) % numDivs;
    setTimeout(start, 3000);
//}
}

Right now I realize I’m kindof using a bootleg method by estimating that each instance is a certain number of pixels apart, and have hard-coded in the number of instances, which isn’t ideal. What is the best way to write this function? The code will be implemented at http://cornellhub.com/board/

  • 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-04T06:58:03+00:00Added an answer on June 4, 2026 at 6:58 am

    Here’s my shot:

    http://jsfiddle.net/3aBx9/

    Basically, I check the top position of every existence of .threadboard, iterate over each one, add a value to the timer and let it run.

    Creating a cancel button should be as simple as clearTimeout().

    Final edit by original poster, with code modified that works in all browsers. The ultimate solution was to use body, html instead of either body or html, the former which works in webkit browsers and the latter which works in non-webkit browsers. The function and timeout also had to be moved out of the scope of the $(document).ready(function () {. The code below now reflects the edited solution:

    var timeOut = 1500;
    
    function startSurf(winY) {
    //new timeout function
    setTimeout(function () {
        //the page neesd to be animated (relative of course, careful)
        $('body').animate({
    
            //animate the scroll
            scrollTop: winY
    
            //scroll speed
        }, 'fast');
    
        //our timer needs to be declared outside the functin so it doesn't just jump to the end.
    }, timeOut);
    
    //add 1.5 seconds for each iteration loop or it will try to jump to the end.
    timeOut += 1500;
    }
    $(document).ready(function () {
    $('#surf').click(function () {
        var numThreads = $('.threadboard');
    
        $.each(numThreads, function (index, obj) {
            //the position of the object
            var position = $(obj).position();
    
            //the top position of the object (relative of course, careful)
            var winY = position.top;
    
            //on the first iteration
            if (index == 0) {
                $('body').animate({
                    scrollTop: winY
                }, 'fast');
    
                //for every iteration after
            } else {
                startSurf(winY);
            }
        });
    });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In HTML, I have a button list. If user clicks a button, doCommand function
$('.my-button').click(function() { $(.my-textbox).focus() }); Before Jquery 1.4 this used to be the way to
Is there a way to shortcut this: function a($where){ echo $where; } function b(){
What is the most elegant way to implement this function: ArrayList generatePrimes(int n) This
is there any way I can reproduce this ruby function: def Password.hash(password,salt) Digest::SHA512.hexdigest(#{password}:#{salt}) end
Is there any Java function or util class which does rounding this way: func(3/2)
Is this the right way to return an object from a function? Car getCar(string
Is there a way I can get this array walk with my anonymous function
I have this (simplification): $(li).click(function{alert(test);}); <li> <input> </li> What's the best way to bind
I building a page that will depend entirely on JavaScript. Whenever a user clicks

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.