在这种情况下如何使变量全局可访问?

How to make the variable globally accessible in this case?

CODEPEN 示例 http://codepen.io/dada78/pen/b50de869b75b32e220956bb36052733b

我想弄清楚如何使我的 highlightSelection 函数中使用的 selectedId 变量在代码笔第 40 行的函数 "fadeOutUnselected(notThisId)" 中可访问?

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;
}

感谢任何帮助。我想做的就是将用户选择的选项("selectedId" 变量)动画化到位置 y:0.

谢谢!

你应该这样做

var globalSelectedId;

function highlightSelection(label) {
    // same code 
    globalSelectedId = selectedId;
}

function fadeOutUnselected(notThisId) {
    // same code, you can acces globalSelectedID
}