mmsh Posted November 18, 2012 Share Posted November 18, 2012 (edited) Hi, i have many categories and the div.block has a max-height, 'cause i need a scrollbar... how to autofocus the current selected category position? or better, how to scroll to selected list item? I wouldn't the user to see the block from the beginning if the current category is more to the bottom... Can you help me please? Thanks Edited November 19, 2012 by mmsh (see edit history) Link to comment Share on other sites More sharing options...
mmsh Posted November 19, 2012 Author Share Posted November 19, 2012 i have #categories_block_left (with the scrollbar) AND #categories_block_left ul.tree a.selected ... now, the jquery.scrollTo-1.4.2-min.js is already loaded (isn't it?) and so, how to scroll from the first to the last with jquery? and where to put the code? thanks Link to comment Share on other sites More sharing options...
mmsh Posted November 19, 2012 Author Share Posted November 19, 2012 (edited) blockcategories.tpl: i tried with... ... <script type="text/javascript"> // <![CDATA[ // we hide the tree only if JavaScript is activated $('div#categories_block_left ul.dhtml').hide(); // ]]> </script> {literal} <script type="text/javascript"> $(document).ready(function () { $('div#categories_block_left').scrollTo( $('div#categories_block_left ul.tree a.selected'), 1000 ) }); //OR ul.tree a.selected OR a.selected </script> {/literal} but it doesn't work... what's wrong? please help Edited November 19, 2012 by mmsh (see edit history) Link to comment Share on other sites More sharing options...
mmsh Posted November 19, 2012 Author Share Posted November 19, 2012 (edited) oh YES... solved!!! hope this helps for someone {literal} <script type="text/javascript"> $(document).ready(function () { var container = $('#categories_block_left'), scrollTo = $('#categories_block_left ul.tree a.selected'); container.scrollTop( scrollTo.offset().top - container.offset().top + container.scrollTop() ); }); </script> {/literal} Edited November 19, 2012 by mmsh (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts