EchoLazyLoader
Gem for lazily loading the images using Echo javascript library.
Installation
Add this line to your application's Gemfile:
gem 'echo_lazy_loader'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install echo_lazy_loader
Usage
Add the following to your app/assets/javascripts/application.js
:
//= require echo
To use minified version use this:
//= require echo.min
Use the following helper function instead of image_tag
for images that you want to lazily load
echo_image_tag src, options
This function takes same parameters as the image_tag
helper.
You will also have to call the following function ( prefereably in application layout ).
echo_init
If you want to apply lazy loading to images that donot show on scrolling but are swaped by some slider or filter layout , you can directly use this javascript code
<script type="text/javascript">
Echo.render();
</script>
Configuration
you can use rails g echo_lazy_loader:config
that will generate echo_lazy_loader.rb
in project's initializer folder.
The configurable options ( with default values) are as follows.
default_image = "/assets/blankloading.gif"
offset= 100
throttle= 250
default_image
is the path to the image which you want to show when the actual image is loading .
offset
and throttle
are used by the Echo Library
and has been explained in its documentation .
You can also pass the offset
and throttle
while calling echo_init
. The values passed to the function will be used instead of those given in configuration file.
Contributors
- Kinaan Khan Sherwani ( kinaan.khan@confiz.com )
- Usman Ali ( usman.ali@confiz.com)
- Ahmad Hussain ( ahmad.hussain@confiz.com)
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request