By the way I understand it, you want to add the EventListener simultaneously to the elements that have the IDs: animate
, animateServico
, animatePortifolio
.
You can do this by simply adding the other IDs with a comma to the selector , like this:
$("#animate, #animateServico, #animatePortifolio").click(function() {
//ação que você deseja
});
[Edited]
In front of what you said in the comments, contradicting my own statement, you can use the above approach, manipulating with if
itself, which screen you want to open.
There are two ways to open a specific screen, according to the element that was clicked:
Form 1
You can get the id
of the element clicked, and thus, you construct a block if
, like this:
$("#animate, #animateServico, #animatePortifolio").click(function(event) {
//o "event" se faz necessário para obter-se o elemento clicado
let targetId = event.target.id;
if (targetId == "animate") {
//ação 1
} else if (targetId == "animateServico") {
//ação 2
} else if (targetId == "animatePortifolio") {
//ação 3
}
});
Form 2
You can define a data attribute , and then get its value, and according to it, open the desired screen:
<script>
$(document).ready(function() {
$("#animate, #animateServico, #animatePortifolio").click(function(event) {
$('#content').animate({"left": "100%"}, 1500);
$('#' + $(event.target).attr("data-tela")).animate({"right": "100%"},1500);
});
});
</script>
I hope I have helped!