javascript - Slide a div up to match its new contents with jQuery -


i have div contains questions

questions 2: square root of 16?

a. 7 b. 5 c. 4 d. 1 

i need make when answer choice selected, slides , shows:

question 2: correct! (or incorrect!) 

i have working using javascript here:

function finalizeanswer(bttn,c,questionid) {     if (c) {         bttn.parentnode.style.backgroundcolor="lightgreen";         bttn.parentnode.innerhtml="<b>question "+(questionid+1)+":</b> correct!";     } else {         bttn.parentnode.style.backgroundcolor="pink";         bttn.parentnode.innerhtml="<b>question "+(questionid+1)+":</b> wrong!";     }     updatescore(); } 

the div resizes because contents different (no longer long question, short response). possible replace in here make slide instead of popping up?

just reference function included:

bttn -> button pressed. (a, b, c, or d)

c -> if answer correct

questionid -> used data question.

updatescore(); -> function updates score on quiz.

this solution uses jquery animate change in height.

edit: i've updated use true new height instead of magically guessed @ 24px.

see live demo on jsfiddle

function displayresult(container, correct, questionid){       // keep old height     var oldheight = $(container).height();      // change contents     $(container).css('background-color', correct == true ? 'lightgreen' : 'pink');     $(container).html("<b>question " + (questionid+ 1) + ":</b> " + (correct == true ? "correct!" : "wrong!"));          // capture new height     var newheight = $(container).height();      // jump old height , animate new     $(container).css('height', oldheight);     $(container).animate({height:newheight}); }  function finalizeanswer(bttn,c,questionid) {     displayresult(bttn.parentnode, c, questionid);      // have commented out call updatescore since don't have     //updatescore(); } 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -