项目作者: ArunMichaelDsouza

项目描述 :
AngularJS Module to make images appear with transition as they load.
高级语言: JavaScript
项目地址: git://github.com/ArunMichaelDsouza/ng-image-appear.git
创建时间: 2016-03-21T18:15:56Z
项目社区:https://github.com/ArunMichaelDsouza/ng-image-appear

开源协议:MIT License

下载


ng-image-appear icon

ng-image-appear npm version NPM Downloads Latest Stable Version Patreon donate button

AngularJS Module to make images appear with transition as they load.

Wraps the img tag within a wrapper and adds a gif loader in between. No more ugly-looking progressively loading images!

http://arunmichaeldsouza.github.io/ng-image-appear/

Demo on CodePen

ng-image-appear

This project has also been ported to ReactJS - react-image-appear.


Installation

CDN

Use ng-image-appear directly from jsdelivr CDN

  1. https://cdn.jsdelivr.net/npm/ng-image-appear@1.11.15/dist/ng-image-appear.min.js

via bower

You can install the package using bower. Make sure you have bower installed, then run :

  1. bower install ng-image-appear

via npm

  1. npm install ng-image-appear

Or, download the latest version and include ng-image-appear.min.js to your project.

Add ngImageAppear as a dependency in your angular app module.


Usage

Include the directive with an img tag in your HTML file with any of the available options.

Include the src and the ng-image-appear directive as an attribute.

Example -

  1. var myApp = angular.module('myApp', ['ngImageAppear']);
  2. myApp.controller('appCtrl', ['$scope', function($scope) {
  3. }]);
  1. <img
  2. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  3. ng-image-appear
  4. responsive
  5. transition-duration="1s"
  6. animation="fillIn"
  7. animation-duration="1s"
  8. easing="ease-out"
  9. />


Options

transition-duration

This parameter specifies the transition duration for the image to appear. Default value is 700ms.

Example -

  1. <img
  2. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  3. ng-image-appear
  4. transition-duration="4s"
  5. />


bg-color

Adds a background color to the image wrapper element.

Example -

  1. <img
  2. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  3. ng-image-appear
  4. bg-color="#50a4e2"
  5. />

bg-color


no-loader

If this option is specified, then no gif loader is shown in the image wrapper element.

Example -

  1. <img
  2. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  3. ng-image-appear
  4. no-loader
  5. />

no-loader


responsive

Use this option to make the image wrapper responsive. In that case the width of the wrapper is calculated in %, otherwise it is calculated in px.

Example -

  1. <img
  2. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  3. ng-image-appear
  4. responsive
  5. />

responsive


placeholder

Adds a default placeholder in the image wrapper background.

Example -

  1. <img
  2. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  3. ng-image-appear
  4. placeholder
  5. />

placeholder

You can override the default placeholder background and add your own by passing an image link to this option.

Example -

  1. <img
  2. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  3. ng-image-appear
  4. placeholder="http://getuikit.com/docs/images/placeholder_600x400.svg"
  5. />

placeholder-custom


placeholder-class

Use this option to add a CSS class to the placeholder background.

Example -

  1. <style>
  2. .placeholder-css {
  3. background-size: contain;
  4. }
  5. </style>
  6. <img
  7. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  8. ng-image-appear
  9. placeholder
  10. placeholder-class="placeholder-css"
  11. />


placeholder-style

Add CSS styles to the placeholder background using this option.

Example -

  1. <img
  2. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  3. ng-image-appear
  4. placeholder
  5. placeholder-style="background-size: contain;"
  6. />


loader-img

Add a custom gif loader in the image wrapper. Default width and height of the loader is 40px. The image must be a gif.

Example -

  1. <img
  2. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  3. ng-image-appear
  4. loader-img="https://cache.dominos.com/nolo/ca/en/010048/assets/build/images/img/spinner.gif"
  5. />

loader-img


loader-class

Use this option to add a CSS class to the loader element.

Example -

  1. <style>
  2. .loader-css {
  3. width: 60px;
  4. height: 60px;
  5. left: calc((100% - 60px) / 2);
  6. top: calc((100% - 60px) / 2);
  7. }
  8. </style>
  9. <img
  10. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  11. ng-image-appear
  12. loader-class="loader-css"
  13. />


loader-style

Add CSS styles to the loader element using this option.

Example -

  1. <img
  2. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  3. ng-image-appear
  4. loader-styles="width: 60px; height: 60px; left: calc((100% - 60px) / 2); top: calc((100% - 60px) / 2);"
  5. />


animation

Add a CSS3 powered animation to the image as it appears. Default animation is fadeIn.

Example -

  1. <img
  2. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  3. ng-image-appear
  4. animation="bounceIn"
  5. />

animation

ng-image-appear has the following built-in CSS3 animations -

fadeIn (default)
fadeInUp
fadeInRight
fadeInDown
fadeInLeft
bounceIn
bounceInUp
bounceInRight
bounceInDown
bounceInLeft
flipInX
flipInY
zoomIn
blurIn
blurInUp
blurInRight
blurInDown
blurInLeft
fillIn


animation-duration

This parameter specifies the animation duration for the image to appear. Default value is 700ms.

Example -

  1. <img
  2. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  3. ng-image-appear
  4. animation="fillIn"
  5. animation-duration="2s"
  6. />


easing

Specifies the timing-function for the CSS3 powered transition/animation. Default value is ease-in-out.

Example -

  1. <img
  2. src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
  3. ng-image-appear
  4. animation="bounceIn"
  5. easing="ease-out"
  6. />


Contributors


Arun Michael Dsouza


Travis Vignon


Lukas Drgon


Support

If you’d like to help support the development of the project, please consider backing me on Patreon -


License

MIT Licensed

Copyright (c) 2016 Arun Michael Dsouza (amdsouza92@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.