I'm using this plugin to create a horizontal timeline. You can use the left and right arrows to navigate between dates. Clicking on a date will change the footer to the one corresponding to that same date.
My problem is the following: I am trying to know if certain dates are visible in the current viewport. So for instances when the plugin is first loaded the following dates: "16 Jan", "28 Feb", "20 Mar", "20 May" are shown. When I click on the right arrow these dates are replaced by the following dates: "09 Jul", "30 Aug", "15 Sep", "01 Nov". Now, at this point, I would like to know, for example, if the date "16 Jan" is visible or not (In this case it is not visible).
Since each date is added to the a
element that corresponds to each date in the form of a data-date
attribute I can get the element that I want to check with the following selector (example for "16 Jan"):
$("a[data-date='16/01/2014'");
Now in order to check the visibility I have tried two different approaches:
First Approach (as seen in this answer)
$("a[data-date='16/01/2014'").is(':visible');
This approach always returns me true and thus does not work.
Second Approach (as seen in this answer)
function isElementInViewport (el) {
//special bonus for those using jQuery
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
);
}
And afterwards:
var a = $("a[data-date='16/01/2014'");
var b = isElementInViewport();
This approach always returns me true and thus also does not work.
I can understand that these approaches might not work because the way the elements are showing and disappearing after each arrow click is due to the use of the CSS function scaleX(), whose impact I have no idea in this specific situation.
So after all of this my question is the following: Is it even possible to check the visibility of the elements in this specific case? And if so, how can I do it?