Monday, 15 February 2010

javascript - Putting simple functions that contain jquery in a jquery execution queue -



javascript - Putting simple functions that contain jquery in a jquery execution queue -

i have number of functions containing jquery should executed sequentially. aren't used create effects rather position elements @ calculated location within div. online resources on jquery queue focused on creation of transitions or animations it's hard find simple illustration on how execute number of simple functions sequentially.

i have these functions:

function bigitemrecalc(recalc, idbase, innerheight, i) { if (recalc < 0) { $('#' + idbase + i).css('max-height', (innerheight + (2 * recalc))); recalc = 0; } homecoming recalc; } function firstcheck(recalc, idbase, i) { if (i == 1) { $('#' + idbase + i).css('margin-top', recalc * -1); } } function lastcheck(recalc, idbase, itemamount, i) { if (i == itemamount) { $('#' + idbase + i).css('margin-top', recalc); } } function truncateitems(totalheight, widgetheight, idbase, i) { if (totalheight > (widgetheight - 20)) { $('#' + idbase + i).remove(); $('#' + idbase + "b" + i).remove(); } }

in function want execute these sequentially using jquery queue preferably , haven't got clue how.

the code called here:

function stylewidget(itemamount, widgetheight, widgetwidth, idbase) { var innerheight; var outerheight; var recalc; var totalheight = 0; var totalwidth = 0; (var = 1; <= itemamount; i++) { if (widgetheight >= widgetwidth) { totalheight += $('#'+idbase+i).height(); innerheight = $('#' + idbase + i).height(); outerheight = (widgetheight/itemamount); recalc = ((outerheight / 2) - (innerheight / 2)); recalc = bigitemrecalc(recalc, idbase, innerheight, i); $('#' + idbase + i).css('padding-top', recalc); firstcheck(recalc, idbase, i); lastcheck(recalc, idbase, itemamount, i); truncateitems(totalheight, widgetheight, idbase, i); } else { innerheight = $('#'+idbase+i).height(); outerheight = widgetheight; recalc = ((outerheight/2)-(innerheight/2)); $('#'+idbase+i).css('padding-top',recalc); totalwidth += $('#'+idbase+i).width(); if (totalwidth > (widgetwidth-20)) { $('#' + idbase + i).remove(); $('#' + idbase + "b" + i).remove(); } } } }

the bottom part hasn't been updated yet, can ignored it's beingness tested portrait mode widgets.

i think i've found clue. when no delay introduced values of totalheight , innerheight seem low. assume page isn't loaded time script executed. every time new widget generated above script called this:

$(document).ready(stylewidget(3, 225, 169, 'id-871206010'));

this fixed it:why firefox 5 ignore document.ready? seems reloading page did not trigger .ready() function.

javascript jquery multithreading queue

No comments:

Post a Comment