Firstly, I don’t have strong experience working on JS.
I have found the following code in this community and it work perfectly. Basically, it makes when you scroll into view of an element it add a new class (animation).
// Returns true if the specified element has been scrolled into the viewport.
function isElementInViewport(elem) {
var $elem = $(elem);
// Get the scroll position of the page.
var scrollElem = ((navigator.userAgent.toLowerCase().indexOf('webkit') != -1) ? 'body' : 'html');
var viewportTop = $(scrollElem).scrollTop();
var viewportBottom = viewportTop + $(window).height();
// Get the position of the element on the page.
var elemTop = Math.round($elem.offset().top);
var elemBottom = elemTop + $elem.height();
return ((elemTop < viewportBottom) && (elemBottom > viewportTop));
}
// Check if it's time to start the animation.
function checkAnimation() {
var $elem = $('#feedback');
// If the animation has already been started
if ($elem.hasClass('fadeInUp')) return;
if (isElementInViewport($elem)) {
// Start the animation
$elem.addClass('fadeInUp');
}
}
// Capture scroll events
$(window).scroll(function() {
checkAnimation();
});
Original post: Activate CSS3 animation when the content scrolls into view
However, I would like to use this JS with two different Id (#feedback and #goback) however, when I try to add another line to the original, it only works with #goback
var $elem = $('#feedback');
var $elem = $('#goback');
I think it was made to work with only one #.
Could someone help me to fix it in order to make it works with more than 1 id, please?
Thanks PD: If you are thinking to give me a negative point please let me know why.