I would like to know how I get the placement of a given element when it arrives in the center of the window, since I need to animate it when it is centralized. Thank you to reply with jQuery.
I would like to know how I get the placement of a given element when it arrives in the center of the window, since I need to animate it when it is centralized. Thank you to reply with jQuery.
To find the exact center you will have to subtract half the width / height of the element by the width / height of the page.
Example:
posicao = $('.elemento').offset();
centro_horizontal = ($(window).width() / 2) - ($('.elemento').width()/2);
centro_vertical = ($(window).height() / 2) - ($('.elemento').height()/2);
if (posicao.left == centro_horizontal && posição.top == centro_vertical){
alert('elemento no centro');
}
You can use the WayPoint jquery plugin link
Download the plugin, and refer to it in your HTML.
Then use the offset: 50%
parameter, so it's the center of the view.
After that, just do something similar
$('#seu-elemento').waypoint(function() {
alert('Animação acontece quando chegar no meio da página')
}, { offset: '50%' });
I've done an example at link