0

So I am trying to replicate browser scroll bar behavior with div's so far i'm getting nowhere, first let's look at my code, jsFiddle, and the actual code here:

(function( $ ) {
    $.widget( "ui.slider", $.ui.mouse,{

    _create: function() {
        this._mouseInit();
    },

    _mouseDrag: function(e) {
        mouseOffset = (e.offsetY / this.element.height()) * 100;
        handleOffset = (e.target.offsetTop / this.element.height()) * 100;

        $(".handle").css("top", (mouseOffset - handleOffset) + "%");        
    }

    });

}( jQuery ) );

So as you can see I'm using jquery widget to capture mouse events, and as you can see with current code it's going crazy in jsFiddle, what i want to achieve is that wherever you click on scroll the bar and start dragging that bar would go along with the mouse and not jump down or up or to the middle and so on, basically it should work same way it works in browser, any help would be appreciated.

3 Answers 3

1

Just out of curiosity, implementing a scroll bar takes a lot more effort than just handling the scrolling of content.

Would a scrollbar plugin for jQuery be more useful to you?

2
  • No, i actually have most of the stuff done, i just have to solve this one problem and i'll be good to go, so if you could help me with it i would be really grateful.
    – Linas
    Commented Jan 2, 2013 at 22:24
  • Hey, i have tried this plugin but i can't seem to find a way to place scroll bar handle at the bottom, by default it's always at the top but i need it to be at the bottom (100% from the top)
    – Linas
    Commented Jan 7, 2013 at 19:51
0

Here a good scroll bar that works well with the DIV tag. You can customize any way you want it, include your own graphics and colors, sizes and all. It worked for me, but it has a cost.

Check it our at: www.sa-wired.com/scrollbar/plugins.php

Good luck.

0

This one also works pretty well:

https://github.com/mzubala/jquery-custom-scrollbar

and is very simple to install.

1
  • 1
    Note that link-only answers are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference.
    – kleopatra
    Commented Oct 2, 2013 at 14:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.