-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] JQuery Lazy + smooth scrolling to anchor #98
Comments
Hello @Kristinita Without see it it's hard to be 100% sure (your page was not available at this time), but I belive that problem belongs to how the scrips work. I mean, think about what happen: On page load, there is no image loaded jet. You click on a link and smooth scroll figures out where (in pixel) the element you want to scroll to is located. Then the scrolling is applied. Now, on the way scrolling down, you reaches new images. Lazy will start loading these images and the content becomes bigger and bigger. But the smooth scroll still thinks the end location is on a given point and stop there. So in general everything works as espected, but you forgot about how things work. 😉 |
An Idea: A solution would be to give all your images, you want to lazy load, the exactly width and height. That would prevent that the content changes it's size on scrolling down. |
I'll close this here because of no more response and because this seems not to be an issue with lazy itself. |
Why “not to be an issue with lazy itself”? I simplify an example. No Gemini Scrollbar, no smooth scrolling, only JQuery Lazy. 1. SummaryIf I use JQuery Lazy and click to anchor link: scrollbar does not reach header. 2. SourceOn Codepen: Significant parts of source: <script src="//cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/jquery.lazy/latest/jquery.lazy.min.js"></script>
<script src="//cdn.jsdelivr.net/jquery.lazy/latest/jquery.lazy.plugins.min.js"></script>
<script>
$(function() {
$('.SashaLazy').Lazy();
});
</script>
<p><img class="SashaLazy" src="https://kristinita.ru//theme/images/interface-images/transparent-one-pixel.png" data-src="https://kristinita.ru/theme/images/404/SashaNose.png" alt="SashaGreenSweater"></p>
<p><img class="SashaLazy" src="https://kristinita.ru//theme/images/interface-images/transparent-one-pixel.png" data-src="https://kristinita.ru/theme/images/aside/SashaGreenSweater.jpg" alt="SashaGreenSweater"></p> 3. Demonstration
4. Expected behaviorScrollbar move to Relevance word. 5. Actual behaviorScrollbar move to images. 6. Exactly width and height
Any ideas? Thanks. |
Simply think about how things work and what you do there. You click on a link to scroll to this element/id. The browser looks where the element is located in page, and scrolls to it. But on the way down, Lazy will load the images in between (as it should be). But then, the location of the original element is not on the same spot as before loading the images. So this can't work as you expect. But this is not an issue of Lazy, you will get this problem whenever you change the page while scrolling. If you want to use Lazy and want to scroll to elements, you need to give your images fixed dimensions, so the browser known the size of the not loaded elements before scrolling. |
Another option would be using some kind of step function to re-evaluate the target's position on scroll - tried getting that to work with jQuery's
seems to work for me. |
1. Problem
If I use:
My scrollbar do not scroll to expected anchor.
If
or
I can successful use smooth scrolling to expected anchors.
2. Actual behavior
Demonstration video.
I click to 3.5.1 item, but scrollbar scroll to 3.1.2 item for me.
3. Settings
My page in demonstration video — http://kristinita.ru/Sublime-Text/SashaSublime
My script of Gemini, JQuery Lazy and smooth scrolling:
This script based on your and @noeldelgado answers.
4. Did not help
Thanks.
The text was updated successfully, but these errors were encountered: