Search code examples
javascriptvariablesscopegsap

How to make the variable globally accessible in this case?


CODEPEN Example http://codepen.io/dada78/pen/b50de869b75b32e220956bb36052733b

I am trying to figure out how to make the selectedId variable used in my highlightSelection function accessible in my function "fadeOutUnselected(notThisId)" on line 40 in the codepen?

function fadeOutUnselected(notThisId) {
var tl = new TimelineMax();

tl.to(".options:not([id=" + notThisId +"]), input[type='radio']", 0.5, {autoAlpha:0}, "getSlidesReady+=4") //fade out all options but the selected one  
//.to("#"+ selectedId, 0.5, {y:0}) //animate selectedId option up
  .set(".options:not([id=" + notThisId +"]), input[type='radio']", {y:0})
return tl;
}

Any help appreciated. All I would like to do is animate the option the user selects ("selectedId" variable) up to position y:0.

Thanks!


Solution

  • You should do something like

    var globalSelectedId;
    
    function highlightSelection(label) {
        // same code 
        globalSelectedId = selectedId;
    }
    
    function fadeOutUnselected(notThisId) {
        // same code, you can acces globalSelectedID
    }