Jquery - Scrollbar

Asked

Viewed 167 times

4

I’m developing a scroll bar in JQuery for an element, a div, I need the bar to be the right size to scroll, I’m posting the code with the error to see if you help me:

Codepen

It gets the bar of a non-responsive size, I tried to use $( window ).width() in the measurement but failed.

  • What is the right size? Is it the size of the window? You do not set the size of the scroll bar, you set the size of the div where the scroll is

  • the bar has q be proportional of the content and the size of the div, if the content is larger it is smaller and if the content is smaller it is bigger......

  • Um, I don’t quite get it. There’s some example you’re following?

  • what’s in the codepen

  • Dude, you can explain the question better, which exactly is proportional. And it’s not proportional or responsive??

  • if you enable the overflow will notice that the bar I created is different from the browser bar and would have to be the same size because it has q function as if it were the browser bar!

Show 1 more comment

1 answer

1


that would be it? http://codepen.io/goblinbr/pen/dXPLoW

function barra() {
    var larguraVisivel = $(".conteudo").width();
    var larguraTotal = $(".conteudo2").width();

    var perc = larguraVisivel / larguraTotal;
    var tamanho = larguraVisivel * perc;

    var left = $(".conteudo").scrollLeft() * perc;
    $(".barra1").css('margin-left', left);
    $( ".barra1" ).width(tamanho);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.