javascript - Page jumping after link click - jQuery AJAX call -
i'm making ajax call on link click, every time click, jumps few hundred pixels (not top of page. doing wrong here?
// handle gallery nav click $('.gallery-nav-buttons a').click(function(e) { e.preventdefault(); updateimages('#image-container', $(this).attr('href')); return false; }); function updateimages(div, url) { // show loader $('.gallery-loader').show(); // delete current images , hide div $(div).empty(); $(div).hide(); // json getjsonimages(url).then(function(data){ // each image, render html , append div data.data.foreach(function(image) { // append images div var html = constructimagehtml(image); $(div).append(html); // hide loader $('.gallery-loader').hide(); // show image div $(div).fadein(1000); }); // set prev link if (typeof(data.links.prev) != "undefined") { $('.gallery-nav-prev').attr('href', data.links.prev); $('.gallery-nav-prev').removeclass('disabled'); } else { $('.gallery-nav-prev').addclass('disabled'); } // set next link if (typeof(data.links.next) != "undefined") { $('.gallery-nav-next').attr('href', data.links.next); $('.gallery-nav-next').removeclass('disabled'); } else { $('.gallery-nav-next').addclass('disabled'); } return false; }); } function getjsonimages(url) { return $.ajax({ url: url, datatype: 'json', type: 'get' }); }
add below code in ajaxstop() or successs function of ajax call
$(div).empty(); $(div).hide();
Comments
Post a Comment