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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:20:31+00:00 2026-05-24T22:20:31+00:00

You can easily see the problem on the first page here: http://m.vancouverislandlife.com/ Scroll down

  • 0

You can easily see the problem on the first page here: http://m.vancouverislandlife.com/

Scroll down (slide up) and allow the content to leave the page, and it doesn’t bounce back and is lost forever. However, on pages whose content does overflow the page and is therefore supposed to be scrollable, the scrolling works correctly (see Accomodations > b&b’s and scroll down for an example of this).

I noticed that on my computer, the scrolling on the first page is always stuck at -899px. I can’t find anybody else who’s experienced this problem and no matter what I try, I just can’t fix it! Help!

(It’s not exactly urgent, however, as the target audience of iPhones and iPod Touches aren’t affected by this since they have so little screen room.)

Okay, new problem. To solve the iScroll issue, I just created a custom script. However, it’s not working correctly on the actual device. On desktop browsers, it works just fine. On mobile, it occasionally jumps back to the top and won’t recognize some touches. This is probably because of the way I cancelled the default event and had to resort to a bit of a hack. How can I fix this? (Yup – simple problem for a +500 bounty. Not bad, huh?)

Here’s the script, and the website is at the usual place:

function Scroller(content) {
    function range(variable, min, max) {
        if(variable < min) return min > max ? max : min;
        if(variable > max) return max;
        return variable;
    }

    function getFirstElementChild(element) {
        element = element.firstChild;

        while(element && element.nodeType !== 1) {
            element = element.nextSibling;
        }

        return element;
    }

    var isScrolling = false;
    var mouseY = 0;
    var cScroll = 0;
    var momentum = 0;
    if("createTouch" in document) {
        content.addEventListener('touchstart', function(evt) {
            isScrolling = true;
            mouseY = evt.pageY;
            evt.preventDefault();
        }, false);
        content.addEventListener('touchmove', function(evt) {
            if(isScrolling) {
                evt = evt.touches[0];

                var dY = evt.pageY - mouseY;
                mouseY = evt.pageY;
                cScroll += dY;
                momentum = range(momentum + dY * Scroller.ACCELERATION, -Scroller.MAX_MOMENTUM, Scroller.MAX_MOMENTUM);

                var firstElementChild = getFirstElementChild(content);

                content.style.WebkitTransform = 'translateY(' + range(cScroll, -(firstElementChild.scrollHeight - content.offsetHeight), 0).toString() + 'px)';
            }
        }, false);
        window.addEventListener('touchend', function(evt) {
            isScrolling = false;
        }, false);
    } else {
        content.addEventListener('mousedown', function(evt) {
            isScrolling = true;
            mouseY = evt.pageY;
        }, false);
        content.addEventListener('mousemove', function(evt) {
            if(isScrolling) {
                var dY = evt.pageY - mouseY;
                mouseY = evt.pageY;
                cScroll += dY;
                momentum = range(momentum + dY * Scroller.ACCELERATION, -Scroller.MAX_MOMENTUM, Scroller.MAX_MOMENTUM);

                var firstElementChild = getFirstElementChild(content);

                content.style.WebkitTransform = 'translateY(' + range(cScroll, -(firstElementChild.scrollHeight - content.offsetHeight), 0).toString() + 'px)';
            }
        }, false);
        window.addEventListener('mouseup', function(evt) {
            isScrolling = false;
        }, false);
    }

    function scrollToTop() {
        cScroll = 0;
        content.style.WebkitTransform = '';
    }

    function performAnimations() {
        if(!isScrolling) {
            var firstElementChild = getFirstElementChild(content);
            cScroll = range(cScroll + momentum, -(firstElementChild.scrollHeight - content.offsetHeight), 0);
            content.style.WebkitTransform = 'translateY(' + range(cScroll, -(firstElementChild.scrollHeight - content.offsetHeight), 0).toString() + 'px)';
            momentum *= Scroller.FRICTION;
        }
    }

    return {
        scrollToTop: scrollToTop,
        animationId: setInterval(performAnimations, 33)
    }
}

Scroller.MAX_MOMENTUM = 100;
Scroller.ACCELERATION = 1;
Scroller.FRICTION = 0.8;
  • 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-24T22:20:31+00:00Added an answer on May 24, 2026 at 10:20 pm

    I think Andrew was on the right track with regards to setting the height of the #wrapper div. As he pointed out that,

    that.maxScrollY = that.wrapperH - that.scrollerH;
    

    Normally, this would work. But now that you’ve changed your #content to position: fixed, the wrapper element is no longer “wrapping” your content, thus that.wrapperH has a value of 0, things break.

    Disclaimer: I did not go through the entire script so I may be wrong here

    When manually setting a height to #wrapper, say 500px, it becomes,

    that.maxScrollY = 500 - that.scrollerH;
    

    The folly here is that when there’s a lot of content and the window is small, that.scrollerH is relatively close in value to 500, say 700px. The difference of the two would be 200px, so you can only scroll 200 pixels, thus giving the appearance that it is frozen. This boils down to how you set that maxScrollY value.

    Solution (for Chrome browser at least):

    Since #wrapper effectively contains no content, we cannot use it in the calculations. Now we are left with the only thing that we can reliably get these dimensions from, #content. In this particular case, it appears that using the content element’s scrollHeight yield what we want. This is most likely the one that has the expected behavior,

    that.maxScrollY = that.scrollerH - that.scroller.scrollHeight;
    

    scrollerH is the offsetHeight, which is roughly the height of what you see in the window. scroller.scrollHeight is the height that’s considered scrollable. When the content does not exceed the length of the page, they are roughly equivalent to one another. That means no scroll. When there are a lot of content, the difference of these two values is the amount of scroll you need.

    There is still a minor bug, and this looks like it’s already there. When you have a lot of content, the last few elements are covered up by the bar when scrolled to the bottom. To fix this, you can set an offset such as,

    that.maxScrollY = that.scrollerH - that.scroller.scrollHeight - 75;
    

    The number 75 arbitrary. It’s probably best if it’s the height of the bar itself with 2 or 3 pixels for a bit of padding. Good luck!

    Edit:

    I forgot to mention last night, but here are the two sample pages that I used in trying to debug this problem.

    Long page
    Short page

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

Sidebar

Related Questions

I am using jQuery Form Plugin http://jquery.malsup.com/form/ to submit my form. Here is the
In VB.Net you can easily get the text value of the first child element
I can easily check IP addresses programmatically, but is there any way to set
I can easily calculate the age of a lead in minutes with a formula
I can easily ascend the class hierarchy in Ruby: String.ancestors # [String, Enumerable, Comparable,
We can easily alert anything in java script. Is it possible to get this
You can easily swap two deployments between staging and production environment in the Azure
In F# I can easily do let a = [1 .. 10];; Then why
In Bash I can easily do something like command1 && command2 || command3 which
From Eclipse I can easily run all the JUnit tests in my application. 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.