JavaScript Custom scrollbar using pure JavaScript and CSS custom scrollbar using css,custom scrollbar using javascript,custom scrollbar

I want to create a customized scrollbar with pure CSS3 and JS. This should be done using div elements. Please avoid plugins and overflow-scroll. The content div may contain any element like p, ul or image.

I know how to move elements by using offset values. Do you have any ideas how to create such a scrollbar?

Answer:1

I know you said no plugins but you may want to check out the small function shown on this page which will provide what you're looking for:

http://www.solutoire.com/experiments/scrollbar/index.html

Basically, the code looks as so:

function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
                var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
                var slider = new Slider(scrollbar, handle, {    
                    steps: steps,
                    mode: (horizontal?'horizontal':'vertical'),
                    onChange: function(step){
                        // Scrolls the content element in x or y direction.
                        var x = (horizontal?step:0);
                        var y = (horizontal?0:step);
                        content.scrollTo(x,y);
                    }
                }).set(0);
                if( !(ignoreMouse) ){
                    // Scroll the content element when the mousewheel is used within the 
                    // content or the scrollbar element.
                    $$(content, scrollbar).addEvent('mousewheel', function(e){  
                        e = new Event(e).stop();
                        var step = slider.step - e.wheel * 30;  
                        slider.set(step);                   
                    });
                }
                // Stops the handle dragging process when the mouse leaves the document body.
                $(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
            }

            window.addEvent('domready', function(){             
                // -- first example, vertical scrollbar --
                makeScrollbar( $('content1'), $('scrollbar1'), $('handle1') );
                // -- second example, horizontal scrollbar --
                makeScrollbar( $('content2'), $('scrollbar2'), $('handle2'), true );
                // -- third example, horizontal and vertical scrollbars
                makeScrollbar( $('content3'), $('scrollbar3'), $('handle3'), false );
                makeScrollbar( $('content3'), $('scrollbar4'), $('handle4'), true, true );  
            });
Answer:2

I have a web page that creates a list of contacts and their email addresses. You have two options for the mailto link, (1) open it in the current window or (2) open it in a new tab/window. I see ...

I have a web page that creates a list of contacts and their email addresses. You have two options for the mailto link, (1) open it in the current window or (2) open it in a new tab/window. I see ...

  1. mailto link open in gmail
  2. mailto link open outlook
  3. mailto link open in new tab
  4. mailto link open owa
  5. mailto link open chrome
  6. mailto link open browser
  7. mailto links open in chrome instead of outlook
  8. mailto link doesn't open outlook
  9. click mailto link open outlook
  10. mailto link doesn't open outlook 2016
  11. mailto link won't open outlook
  12. outlook mailto links open in chrome
  13. mailto javascript open link
  14. open mailto link
  15. how to make mailto link open in outlook
  16. open mailto link jquery
  17. open mailto link in yahoo

I have an ajax success response from one html but I want to set dynamic data of this ajax response to another how do I do that here is my ajax report success: function(data) { console....

I have an ajax success response from one html but I want to set dynamic data of this ajax response to another how do I do that here is my ajax report success: function(data) { console....

I'm looking at a node.js library (gen-readlines) that reads large flat files via a generator - i.e. a file is read in 'chunks' of 65 536 bytes at a time via a generator. Not having a CS background I ...

I'm looking at a node.js library (gen-readlines) that reads large flat files via a generator - i.e. a file is read in 'chunks' of 65 536 bytes at a time via a generator. Not having a CS background I ...

I have an app that runs in the client browser and doesn't have any server side (http/js is served, but nothing posts to the server). the app is redeployed on many servers (iis, apache, nginx, ...

I have an app that runs in the client browser and doesn't have any server side (http/js is served, but nothing posts to the server). the app is redeployed on many servers (iis, apache, nginx, ...