I have a button which scroll to a "target" div when pressed. The button and the target div are being injected as an external widget to the site. the function of the button:
scrollToElement = function() {
jQuery([document.documentElement, document.body]).animate({
scrollTop: jQuery(".targetElementClass").offset().top - 10
}, 1000);
//other code
}
It seems that when page load the first press on the button scroll to a different location of the page.this only happen during the page load as it seem there is some kind of race condition between the scroll top calculation and the actual location of the "target" div during the load.
I thought of "stop(true,true).animate(......)" but as I read from the documentation it can stop other animation on the page so I think it may interfere with the customer site functionality and I ruled that out (please let me know if I'm wrong).
Do I have another option except the stop function to try and counter this issue? Also I wonder if that behavior can be caused by other code performing "jQuery().stop()" and is there some kind way of resolving such collision?