I have a jquery function where I repeat the .red way too many times.
I would like to replace them for $(this) instead, but I don't know the correct way to do it apparently.
$(".red").ready(function () {
$(this).addClass("active");
});
This is a simplified version of the code and how I'd want it to behave, hope it makes sense to you guys.
The idea here is to be able to replace that initial .red and have it apply on all the lines of code I add inside the function.
Regards.
EDIT: I was trying to simplify it to the maximum because I use to get lost in complex explainations and because I'm kind of embarrased posting my crappy code lol, here is the code I want to optimize:
function showRed() {
$(".red").show();
if (position == 0) {
$(".red").css({opacity : "0", left: "0"}).transition({opacity:1}, 500, ezin);
} else if (position < 1){
$(".red").css({left : "100%", });
} else if (position > 1) {
$(".red").css({left : "-100%", });
}
position = 1;
goodbye();
$(".red").css({scale: "1"}).transition({left:0}, 500, ezin).addClass("active");
}
function showGreen() {
$(".green").ready(function(){
$(".green").show();
if (position == 0) {
$(".green").css({opacity : "0", left: "0"}).transition({opacity:1}, 500, ezin);
} else if (position < 2){
$(".green").css({left : "100%", });
} else if (position > 2) {
$(".green").css({left : "-100%", });
}
position = 2;
goodbye();
$(".green").css({scale: "1"}).transition({left:0}, 500, ezin).addClass("active");
});
}
What I want is to optimize all this so I don't have to write this code for every single slide. I'm using jQuery transit by the way, transition is pretty much like animate in here.
It's the same for showBlue too.
And this is how it works: http://dlacrem.16mb.com/dlatest/positions.html