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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:20:26+00:00 2026-05-13T17:20:26+00:00

Here’s a long one. I’m trying to implement horizontal scrolling in my site. It’s

  • 0

Here’s a long one. I’m trying to implement horizontal scrolling in my site. It’s working fine in Safari and Chrome, but not in Firefox (I’ll not get started on IE’s issues just yet).

From what I can tell, Webkit is using the relative position of the scroll bar grabber div, while firefox is taking it’s position relative to the document.

You can test it here to see what’s happening.

Here’s the CSS for the scroll bar

/* The Scrollbar */
#scrollbar
{
    position: relative;
    width: 70%;
    display: block;
    margin: 0px auto;
    border: #444444 1px solid;
    border-width: 0 0 1px 0;
    overflow: visible;
}

#grabber
{
    position: relative;
    top: 8px;
    left: 0px;
    height: 20px;
    display: block;
    background: url(assets/grabber-left.png) no-repeat;
}

#grabber-end
{
    height: inherit;
    width: 50%;
    background: url(assets/grabber-right.png) no-repeat;
    background-position: 100% 0;
    float: right;
}

And the jQuery that powers it

var grabberClicked = false;
var dragStart;
var grabberStart;
var ratio;
var scrollBound;
var totalWidth = 0;

// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

$(document).ready(function(){

    $("#projects").width(getTotalWidth());
    setup();
    $("#grabber").mousedown(startScroll);
    $(window).mouseup(endScroll);
    $("#viewport").scroll(positionGrabber);
    $(window).resize(setup);


});

function getTotalWidth(){

    $(".project").each(function(){

        totalWidth += $(this).width();
        totalWidth += parseInt($(this).css("marginLeft")) * 2;

    })

    return totalWidth;

}

// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function setup(){
    ratio = $("#viewport").width() / $("#projects").width();

    // grabber width
    $("#grabber").width( $("#scrollbar").width() * ratio );
    scrollBound = $("#scrollbar").width() - $("#grabber").width();

    // incase the user resizes the window, position the grabber accordingly
    positionGrabber();
}

// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function startScroll(event){
    $(window).bind('mousemove', scroll);
    var position = $("#scrollbar").position();
    dragStart = event.pageX - position.left;
    grabberStart = parseInt($("#grabber").css("left"));
    $("#feedback").html($("#grabber").position().left);
}

// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function endScroll(event){
    $(window).unbind('mousemove', scroll);
}

// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function scroll(event){ 
    var newPos = grabberStart + (event.pageX - dragStart);
    //$("#feedback").html($("#grabber").position().left +" // "+ newPos);

    // bounds
    newPos = (newPos > 0) ? newPos : 0;
    newPos = (newPos < scrollBound) ? newPos : scrollBound;

    viewportPos = ( $("#projects").width() * ( newPos / $("#scrollbar").width() ) );
    $("#viewport").scrollLeft(viewportPos);
    $("#grabber").css("left", newPos);

}

// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function positionGrabber(event){
    var grabberPos = $("#scrollbar").width() * ($("#viewport").scrollLeft() / $("#projects").width());
    $("#grabber").css("left", grabberPos);
}

Any ideas? I know I should know the answer to this, but I’ve been staring at it so long I’m blind to it.

cheers

  • 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-13T17:20:26+00:00Added an answer on May 13, 2026 at 5:20 pm

    I messed around a bit with your code, I think the problem is that position.left returns the position of the object relative to the window and it was returning the scrollbar position. So just changing the position variable from #scrollbar to #grabber worked for me.

    var position = $("#grabber").position();
    

    and because of this, you don’t need to save the grabberStart position

    Lastly, for some reason, and this took me a while to figure out, IE doesn’t like binding to window events. So I switched them to document and BAM! IE is working perfectly.

    Here is you script updated with the changes I mentioned. Nice looking site by the way!

    // **********************************************
    // Throll: Toms Horizontal Scroll 
    // Developer: Tom Elders
    // Contact: him@tomelders.com
    // **********************************************
    // File: throll.1.0.js
    // Description: 
    // CSS and JS horizontal scriolling that doesn't
    // break the browers native functionality. 
    //
    // Copyright 2010, Tom Elders
    //
    // **********************************************
    
    var grabberClicked = false;
    var dragStart;
    var ratio;
    var scrollBound;
    var totalWidth = 0;
    
    // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    $(document).ready(function(){
    
        $("#projects").width(getTotalWidth());
        setup();
        $("#grabber").mousedown(startScroll);
        $(document).mouseup(endScroll);
        $("#viewport").scroll(positionGrabber);
        $(window).resize(setup);
    
    
    });
    
    function getTotalWidth(){
    
        $(".project").each(function(){
    
            totalWidth += $(this).width();
            totalWidth += parseInt($(this).css("marginLeft")) * 2;
    
        })
    
        return totalWidth;
    
    }
    
    // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    function setup(){
        ratio = $("#viewport").width() / $("#projects").width();
    
        // grabber width
        $("#grabber").width( $("#scrollbar").width() * ratio );
        scrollBound = $("#scrollbar").width() - $("#grabber").width();
    
        // incase the user resizes the window, position the grabber accordingly
        positionGrabber();
    }
    
    // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    function startScroll(event){
        $(document).bind('mousemove', scroll);
        var position = $("#grabber").position();
        dragStart = event.pageX - position.left;
    }
    
    // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    function endScroll(event){
        $(document).unbind('mousemove', scroll);
    }
    
    // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    function scroll(event){ 
        var newPos = event.pageX - dragStart;
    
        // bounds
        newPos = (newPos > 0) ? newPos : 0;
        newPos = (newPos < scrollBound) ? newPos : scrollBound;
    
        viewportPos = ( $("#projects").width() * ( newPos / $("#scrollbar").width() ) );
        $("#viewport").scrollLeft(viewportPos);
        $("#grabber").css("left", newPos);
    
    }
    
    // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    function positionGrabber(event){
        var grabberPos = $("#scrollbar").width() * ($("#viewport").scrollLeft() / $("#projects").width());
        $("#grabber").css("left", grabberPos);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is shown how to use styles in CamelCase, but how to use styles
Here is my object constructor static class Edge { int source; // source node
here a a piece of code that is supposed to loop over and over
Here is my code: PtyView *v = [[PtyView alloc] init]; [v sendData([charlieImputText stringValue])]; in
Here is an example table: ID time data type 0 0100 xyz 0 1
here i am again in my self learning hibernate and personal experiment project to
Here is a synopsis of my code which is a moderately complex WinForms GUI.
Here I had a problem that I am adding contact from the address book
Here is my situation. My solution structure is as follows. Project Used to handle
Here's my code $string = preg_replace(/rad\:([0-9]+)px\;\s+\/\*\sALT\[(.+)\*\/|rad\:([0-9]+)px\;/,($2?$2:$1),$string); Basically, in the regex I've got a pipe

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.