Pass in var as a method
Pass in var as a method
Hi,
I'm stumped trying to figure out if this is possible. I'm creating a function to show/hide a menu when clicking an anchor. I want to determine the effect it uses by passing it in as a variable but it no likey!
What am I doing wrong? Check out the code below...
- <script>
function clickMenu(menu, trig, tran)
// hide menu
jQuery(menu).hide();
// setup transitions
var t;
if (tran=='slide') {t = ['slideDown()','slideUp()']}
else if (tran == 'fade') {t = ['fadeIn()','fadeOut(']}
else {t = ['show()','hide()']}
// setup click toggle
jQuery(trig).toggle(
function() {
var e=t[0];
jQuery(menu).e;
console.log(e);
},
function() {
var e=t[1];
jQuery(menu).e;
console.log(e);
}
);
}
jQuery(function(){clickMenu('.share-list','.share','slide')});
</script>
<a href="#" class="share show">Share</a>
<ul class="share-list">
<li><a href="#">Facebook</a></li>
<li><a href="#">Twitter</a></li>
</ul>