jquery - I have a horizontal scroll with overflow hidden, how do i make it scroll to the center when i click it? -
i want make when click on each number, number scroll center of container. here's got far in jsfiddle. https://jsfiddle.net/bf3nv33d/2/
here codes..
html <div id='container'> <div id='scrollbox'> </div> <div id='display'> </div> </div> css #container{ border:1px solid blue; height:200px; width:200px; } #scrollbox{ height:43px; overflow-x:scroll; overflow-y:hidden; white-space:nowrap; } .numberbox{ display: inline-block; background-color: white; padding: 2px 2px 2px 2px; width:20px; border-right:1px solid green; } jquery for(var i=1; i<21; i++){ var numberbox = "<div class='numberbox numberbox"+i+"'>"+i+"</div>"; $('#scrollbox').append(numberbox); } $('.numberbox').on('click', function(){ $('.numberbox').css('background-color', 'white'); $(this).css('background-color', 'yellow'); $('#scrollbox').animate({ scrollleft: $('.numberbox4').offset().left}, 200); });
for(var i=1; i<21; i++){ var numberbox = "<div class='numberbox' id='"+i+"'>"+i+"</div>"; $('#scrollbox').append(numberbox); } $('.numberbox').on('click', function(){ $('.numberbox').css('background-color', 'white'); $(this).css('background-color', 'yellow'); $('#scrollbox').animate({ scrollleft: this.id*25-112.5}, 200); });
#container{ border:1px solid blue; height:200px; width:200px; } #scrollbox{ height:43px; overflow-x:scroll; overflow-y:hidden; white-space:nowrap; } .numberbox{ display: inline-block; background-color: white; padding: 2px 2px 2px 2px; width:20px; border-right:1px solid green; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id='container'> <div id='scrollbox'> </div> <div id='display'> </div> </div>
is looking for? used id
track box number , move location, plus halfway across put in middle.
Comments
Post a Comment