javascript - How to scroll pallet horizontally when i Next and Prev button? -
i newbie development. want scroll question pallet , down according question number when click next , previous buttons.
my pallet div contains more 200 questions (dynamically). has less 200 questions.
below minimal code:
under next button have write following function
function next(id) { if (id >= 40 && id < 79) { $(".question-container").animate({scrolltop: 370}, 'fast'); } if (id > 80 && id < 119) { $(".question-container").animate({scrolltop: 740}, 'fast'); } if (id > 120 && id < 159) { $(".question-container").animate({scrolltop: 1110}, 'slow'); } if (id >= 160 && id < 200) { $(".question-container").animate({scrolltop: 1480}, 'slow'); } if (id >= 200 && id < 240) { $(".question-container").animate({scrolltop: 1850}, 'slow'); } if (id >= 240 && id < 300) { $(".question-container").animate({scrolltop: 2220}, 'slow'); }
anyone able me?
thanks thangavel
a simple solution use window.scrollto()
after detecting top position of target element.
function goto(item) { var top = document.getelementbyid(item).offsettop; window.scrollto(0, top); }
p { height: 800px; }
<button onclick="goto('one')">scrol element</button> <p></p> <div id="one">one element</div>
as alternative use jquery plugin "carousel". there many online, mine own version available here if interesting give try: https://github.com/gibbok/jquery-slidertv
Comments
Post a Comment