javascript - Scroll to top in a lightbox -
i have created customized menu. see here. on click of link have shadowbox popping has long list of items. want have "back top" anchor link takes me top of menu list.
i've set lightbox #box
id.
html
<div id="box"> ... <!-- long content there --> <a href="#" id="totop">to top</a> </div>
css (setting width of elements)
#box { position:relative; width:200px; height:250px; overflow:auto; } #box #totop { position:absolute; display:none; left:150px; top:10px; }
jquery
$('#box').bind('scroll', function(e) { if ($(this).scrolltop() > 100) { $('#totop').fadein(); $('#totop').css({'top' : $(this).scrolltop() + 100}); } else { $('#totop').fadeout(); } }); $(document).on('click', '#totop', function(e) { e.preventdefault(); //$('#box').scrolltop(0); //just go top $('#box').animate({scrolltop : 0},'slow'); //animate });
fiddle
javascript
No comments:
Post a Comment