#7 Material cards

In the previous post, we added tabs to our Polymer Chrome App. Now we add some content to the first tab - CARDS. This may be seem a little off-topic but I will be using Angular Material JS, to show that one need not rely on Polymer for implementation of material design.

The Angular Material project is an implementation of Material Design in Angular.js.

bower install angular-material --save

Include the following Angular Material dependencies.

<!--Angular-Material Dependencies-->
  <link rel="stylesheet" href="bower_components/angular-material/angular-material.css" type="text/css">
  <script src="bower_components/angular/angular.js"></script>
  <script src="bower_components/angular-material/angular-material.js">

Now we use core-animated-pages, where we add content to tabs using sections.
Here is a little help where the Tab content should go....

<!--Main Toolbar-->

      ** Toolbar heading **
      ** Dropdown Menu **
    ** Paper-Tabs **
  <!--Main content goes here-->
     <!--First Tab-->
        * First Card *
        * Second Card *
        * Third Card *
     <!--Second Tab-->

Now it's easy for you guys to put the stuff...I am adding only one card, rest you can add yourself.

<core-animated-pages selected="0" transitions="cross-fade">
 <!--First Tab-->
  <section vertical layout center>
   <!--first card-->
   <md-card cross-fade class="card">
    <img src="assets/forest-patrol.jpg" class="md-card-image" alt="image caption">
     <h2>Green Essence</h2>
     <p>Take a deep breath and dive into the beauty of nature.</p>
    <div style="display:flex;flex-direction:row;justify-content:space-between;">
     <md-card-footer >
      Author: Akshay
     <paper-button style="color: #FF6600;align-self:center;">Take me there</paper-button>
 <!--Second Tab-->
  <section vertical layout center><h1 cross-fade>Hello World</h1></section>

A little tweak to show cards perfectly...

.card {
 width: 65%;
 border-radius: 4px;
.md-card-image { /*coz image borders are not automatically curved*/
 border-top-left-radius: 4px;
 border-top-right-radius: 4px;

But wait...nothing happens when you click the other tab. My friend, you forgot the javascript.

var tabs = document.querySelector('paper-tabs');
var pages = document.querySelector('core-animated-pages');

  pages.selected = tabs.selected;

Yes, now it's working.

  1. When you use polymer elements by their element name (like paper-tabs), use document.querySelector, instead of document.getElementById.
  2. Do Not use the cross-fade animation keyword in the "section" tag. Use it instead in the child element like "md-card", "h1", etc.
  3. IMPORTANT -- > Polymer and AngularMaterial may interfere with each other, so this tutorial may not work for you. If it doesn't...try to update Chrome, otherwise Polymer is always there.
                                                                                                                                             Next Post-->

Popular posts from this blog

Extract songs from Saavn app

Double-side Nav Drawer

15 Quotes that prove why Dhoni is The Greatest Captain Indian Cricket has ever seen