Javascript - How to create a promise for creating dynamic elements -
i execute scroll to
function after elements section scroll have been created. thought promises
way go. have tried not working, not sure how write promises right way when not used ajax request: script:
var showmagazinedetail = function showmagazinedetail(id, slug, name, summary, issueimage, magazineimage, page){ images = []; nextimage = 0; imagesindex = 0; loadedimages = []; scrollpoint = document.height; window.location.hash = slug; let createmagazinedetails = new promise((resolve, reject) => { $(".magazine-section").css('visibility', 'visible'); $('#name').text(name); $('#summary').text(summary); $('#cover-image').attr({"src" : '/imagecache/cover/' + issueimage, "alt" : name}); if (magazineimage != '') { $('#issueimage').show(); $('#issueimage').attr({"src" : '/imagecache/medium/' + magazineimage, "alt" : name}); }else { $('#issueimage').hide(); $('#issueimage').attr({"src" : '', "alt" : name}); } // $('body').css('overflow-y', 'scroll'); $.getjson("issue/images", { id: id }, function(result){ if (result.length < 2){ $('.magazine-preview-nav').hide(); } else { $('.magazine-preview-nav').show(); } $.each(result, function(i, value){ images.push(value); }); preload(); }); }); createmagazinedetails.then(() => { $('html,body').animate({ scrolltop: $(".magazine-detail").offset().top - 80 }); }); }; preload = function() { (i = 0; < 4; i++) { if (nextimage < images.length) { var img = new image(); img.src = '/imagecache/cover/' + images[nextimage]; loadedimages[nextimage] = img; ++nextimage; } } }
Comments
Post a Comment