简体   繁体   中英

How to scroll to top an overflow div with jquery?

$('.lb').click(function() {
    $('#modal').hide();

    var id  = $(this).attr('id');
    var dir = '/lightbox/' + id + '.php';

    $('#lightbox').find('#modal').load(dir, function() {
        $('#modal').show();
        $('#lightbox').fadeIn(200);
    });
});

I currently have a dynamic lightbox but everytime I scroll it to the bottom then load a different page, it stays scrolled into the bottom of #modal

I've tried

$('#modal').show();
$('#modal').scrollTop(0);
$('#lightbox').fadeIn(200);

but it doesnt work

any help would be great!

EDIT - forgot to mention that im using http://areaaperta.com/nicescroll/

$('#div').scrollTop(0); 

works fine

LIVE_DEMO

This should work:

$('#lightbox').find('#modal').load(dir, function() {
    $('#modal').show();
    $('#modal').scrollTop(0);
    // Do also
    $('#modal').scrollLeft(0);
    $('#lightbox').fadeIn(200);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM