I'm using TweenMax script to add styles to a div on scrolling. I want to have different styles on different page resolutions. So, I added an if
condition as a solution. How can I use a variable to avoid adding extra codes inside the if
condition?! I added $direction
and only direction
as a variable, but, it seems that it doesn't work.
if (($(window).width() <= 900) && ($(window).width() >= 409)) {
var $direction = 'left';
} else {
var $direction = 'top';
}
$(".softwares").children(".row").each(function(a) {
$(this).delay(150 * a).fadeIn(0, function() {
TweenMax.to($(this), .3, {
$direction: 45 * a,
opacity: 1,
ease: Back.easeOut
})
})
});
I looked upon lot's of questions in stackoverflow, and I used []
to come to a solution, but I could not make it work.
I don't want the code to be like: (the extra code which I want to avoid)
$(".softwares").children(".row").each(function(a) {
if (($(window).width() <= 900) && ($(window).width() >= 409)) {
// opacity: 1, ease: Back.easeOut are extra codes in both conditions
var options = {left: 45 * a, opacity: 1, ease: Back.easeOut};
} else {
var options = {top: 45 * a, opacity: 1, ease: Back.easeOut};
}
$(this).delay(150 * a).fadeIn(0, function() {
TweenMax.to($(this), .3, options) // use options object here
})
});