GithubHelp home page GithubHelp logo

angular-gallery-directive's Introduction

angular-gallery-directive

Build Status

This is a basic SEO-friendly gallery built on AngularJS. Unlike Bootstrap's carousel component, this works with html rendered on the server-side (instead of ng-repeat) so that search bots can crawl the gallery content. You may still use ng-repeat if you don't care about that.

No dependencies other than Angular 1.2+; likely IE9+ only.

Demo: http://fiestah.github.io/angular-gallery-directive/

Install

bower install angular-gallery-directive

Provided Directives

All are required to except for gallery-indicators.

  • gallery: attribute The root scope of the gallery.
  • gallery-window: attribute This "window" element should wrap gallery-items so that it limits the visible portion of the "film strip" by hiding the overflow.
  • gallery-item-list: attribute The "film strip" of the gallery, which is the parent element for all the gallery image/item elements.
  • gallery-item: attribute The individual gallery image/item element.
  • gallery-indicators: attribute optional This generates the typical little round dots on galleries that tell you where in the gallery you're at. Click on it to scroll to the associated item.

CSS and Classes

You'll need this minimal amount of CSS to get it working. Remember to define the dimensions of your [gallery-window], which can be either fixed or fluid in a responsive grid.

If you want margins between items, just add them in CSS:

[gallery-item] + [gallery-item] { margin-left: 20px; }

$scope Functions

Call these anywhere within the scope of gallery:

Scroll one item at a time:

  • scrollToIndex(index): Scroll to the numbered item
  • nextItem(): Scroll to the next item. It will wrap from the last item to the first.
  • previousItem(): Same as next(), but in reverse.

Scroll several items at a time (when gallery is wider than a single item):

  • scrollToScreen(index)
  • nextScreen()
  • previousScreen()

Sugar to check if there’s a previous/next item/screen:

  • hasPreviousItem()/hasNextItem(): Returns whether or not the currently selected item has a preceeding/next item
  • hasPreviousScreen()/hasNextScreen()

Barebones Example:

Your HTML should look something like this:

  <div gallery>
    <!-- The images -->
    <div gallery-window>
      <div gallery-item-list>
        <div gallery-item>
           <img src="/photo-1.jpg" width="300" height="200" alt="">
        </div>
        <div gallery-item>
           <img src="/photo-2.jpg" width="300" height="200" alt="">
        </div>
        <div gallery-item>
           <img src="/photo-3.jpg" width="300" height="200" alt="">
        </div>
      </div>
    </div>

    <!-- The little dots that tell you where you are -->
    <div gallery-indicators></div>

    <!-- Nav actions -->
    <div class="gallery-nav">
      <a ng-click="previousItem()">Previous</a>
      <a ng-click="nextItem()">Next</a>
    </div>
  </div>

Because Angular is awesome, you can markup the gallery however you want (say, add captions to the photos or order elements differently) as long as the directives are declared at the right places.

Similarly for navigation, just trigger previousItem()/previousScreen() or nextItem()/nextScreen() using directives like ng-click wherever you feel like it.

Notes:

  • This uses display: inline-block to inline the gallery items, so watch out for white spaces/line breaks between .gallery-items, which will introduce an extra 4px space between them.

Todos:

  • Support ng-animate
  • Support controller as syntax
  • Keyboard nav support
  • Figure out default/custom templates

angular-gallery-directive's People

Contributors

thatmarvin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.