-
Notifications
You must be signed in to change notification settings - Fork 505
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
Unload on scrollout #39
Conversation
Thanks for this, some great stuff. I have a question or two. Would it be better do you think to cache the initial image source (which might be blank.gif or whatever...), and store that reference on a holder attribute, and unload to that reference rather than another placeholder, as this introduces a third item (unless I've misunderstood your PR). That way there'd be no need for a placeholder, and we just use their original image Thoughts appreciated! |
Hey todd, my first attempt read a |
Yep I saw that. Open to both options, just wondering which you think is best, and of course with heavy images we want to think about mobiles - so the better on mobile option might sway it. :) |
I think it makes more sense to store it on the element, so that it retains the flexibility of being able to specify different placeholder for different images, which is doable now. This is a pretty happy medium, so I am comfortable with it. |
okay my last commit made that change |
Conflicts: README.md dist/echo.js dist/echo.min.js src/echo.js
@toddmotto when merging in the callback work I made it so the callback function would be passed two parameters, the element and the operation being done, |
@toddmotto can this be merged? |
Thanks @raphaeleidus ! 👍 |
This pull requests add 2 configurations option
unload
andplaceholder
unload
is a boolean optionplaceholder
is a stringWhen unload is true, now when the image scrolls out off the screen it will change the image back to the placeholder image. This is valuable for devices with limited memory (mobile devices). Images that are not on display don't need to be kept in memory.
In order to make this work I had to fix a bug where every image above the screen was automatically loaded. If you scroll to the bottom of a echo.js enabled page and refresh, when the page loads you will be at the bottom of the page but all the images above the screen are loaded immediately instead of lazily.
I added two other options for flexibility, but they aren't really needed,
offsetBot
andoffsetTop
. They allow you to individually set the padding above and below the window. They fallback to use theoffset
option if one of them is not provided.