So I have a custom element called my-element and within that element I have a repeating template that displays a bunch of custom elements called my-card. So I was using inline-block to divide the cards in two columns and that worked but since the cards were of different heights there was some ugly white space in between. As per a suggestion from user here on stackoverflow I used column-count to make it work. Visually, it worked but the my-cards on the right column are not interactive.
If I hover under the first column, I can click the my-cards that are supposed to be in the second column.
Despite it not showing in the image above, the my-cards will be of different heights so I need to have a masonry layout. One column in mobile screen width and two columns in tablet+. How can I achieve that?
Here's the code: http://pastebin.com/NFv6ed2T
I don't see any repeats or anything, but why not change your code to use horizonal and vertical layouts? Remove all excess styling except for that.
And the <section> tag probably isn't necessary.
Assuming you include the iron-flex-layout code somewhere...
working code w/simple styling: http://jsbin.com/cetece/1/edit?html,output
<template id="app" is="dom-bind">
<paper-material class="card">
<div class="vertical layout">
<div class="horizontal layout row">
<paper-button raised class="button" data-dialog="loans">Student Loans</paper-button>
<paper-button raised class="button" data-dialog="wage">Minimum Wage</paper-button>
</div>
<div class="horizontal layout row">
<paper-button raised class="button" data-dialog="racism">Racism</paper-button>
<paper-button raised class="button" data-dialog="climate">Climate Change</paper-button>
</div>
<div class="horizontal layout row">
<paper-button raised class="button" data-dialog="privacy">Internet Privacy</paper-button>
<div class="button" > </div>
</div>
</div>
</paper-material>
</template>
This is an example if you need to have the buttons wrap into one row if the container is too small for 2 rows: http://jsbin.com/cetece/2/edit?html,output
Add wrap class to the rows and adjust the styles for a fixed button size and non-fixed wrapping container.
<template id="app" is="dom-bind">
<paper-material class="card">
<div class="vertical layout">
<div class="horizontal layout row wrap">
<paper-button raised class="button" data-dialog="loans">Student Loans</paper-button>
<paper-button raised class="button" data-dialog="wage">Minimum Wage</paper-button>
</div>
<div class="horizontal layout row wrap">
<paper-button raised class="button" data-dialog="racism">Racism</paper-button>
<paper-button raised class="button" data-dialog="climate">Climate Change</paper-button>
</div>
<div class="horizontal layout row wrap">
<paper-button raised class="button" data-dialog="privacy">Internet Privacy</paper-button>
<div class="button" > </div>
</div>
</div>
</paper-material>
</template>
If you need the buttons to go be able to all align horizontally if needed then simply remove all of the row containers, and the vertical layout container, and place all paper-buttons in one single container, such as the paper-material.
Related
everyone!
I wanted to use paper-header-panel with mode waterfall and custom element 'iron-swipeable-pages'. My code looks somehow like this: (it is not the exact copy, just the structure)
<paper-drawer-panel id="drawer" force-narrow>
<div drawer>
<!-- Drawer panel -->
</div>
<div main>
<paper-header-panel id="paperHeaderPanel" mode="waterfall">
<paper-toolbar id="appbar">
<!-- Toolbar content -->
</paper-toolbar>
<iron-swipeable-pages
padding="16"
id="ironSwipeablePages"
edge-swipe-sensitivity="30"
selected="{{selected}}">
<div id="overview">
1
</div>
<div id="timetable">
2
</div>
<div id="teachers">
3
</div>
<div id="calendar">
4
</div>
</iron-swipeable-pages>
</paper-header-panel>
</div>
</paper-drawer-panel>
The <div> elements inside <iron-swipeable-pages> are scrollable but when I scroll them the waterfall effect on paper-header-panel isn't working.
I tried this:
this.$.paperHeaderPanel.scroller = this.$.overview;
In ready script of element because I saw that property isn't marked as read-only in element reference. However, it does not work. Do you have any ideas how to make waterfall effect work?
As part of my page I have a list that I need to attach a scroll bar too. The entire page is within a paper-header-panel. If I give the paper-scroll-header-panel a height in pixels then it displays fine but otherwise, even if I set it to "width: 100%" it will not display. It seems it ought to be easier then I am trying to make it. are there any tips you can send along as to what I might be doing wrong?
David
<paper-header-panel class="flex">
<paper-toolbar>
<div>MyViewer</div>
</paper-toolbar>
<div class="horizontal layout flex">
<div class="flex">
<paper-scroll-header-panel>
<paper-toolbar>
<div>Hello</div>
</paper-toolbar>
<div>
<h4>here 1</h4>
<h4>here 2</h4>
<h4>here 3</h4>
<h4>here 4</h4>
<h4>here 5</h4>
</div>
</paper-scroll-header-panel>
</div>
<div>
<h2>Stuff</h2>
</div>
</div>
</paper-header-panel>
Your paper-scroll-header-panel displays fine if you display it by itself. Maybe this is why it's not displaying in your sample:
The documentation for paper-scroll-header-panel says:
Important: The paper-scroll-header-panel will not display if its parent does not have a height.
https://elements.polymer-project.org/elements/paper-scroll-header-panel
Is there any way to change polymer core-icon on core-collapse collapse without using jquery ?
This is my code
<template repeat="{{contacts}}">
<div style="margin-top:10px;" class="page-holder contact-dropdown dropdown-holder " horizontal layout center center-justified
on-tap="{{toggle}}" ident="{{cardID}}">
<div><img src="http://lorempixel.com/80/80"></div>
<div flex style="margin-left:15px;">
<p class="user-name">Name</p>
<p class="user-dropdown-info">City <span class="blue bold"
style="margin-right:15px;">City</span> nr <span
class="red bold">297493</span></p>
</div>
<div> <core-icon style="margin-left:-10px;" ident="{{oldIcon}}" class="down-icon" icon="arrow-drop-down"></core-icon>
<core-icon style="margin-left:-10px;display: none; " ident="{{newIcon}}" class="down-icon" icon="arrow-drop-up"></core-icon></div>
</div>
<div class="page-holder dropdown-holder" horizontal layout center center-justified>
<core-collapse class="collapse-content" id="{{cardID}}">
<div class="page-holder page-border" horizontal layout center center-justified>
<div>
<core-icon class="dropdown-icon collapsed-holder" icon="fa:phone"></core-icon>
</div>
<div flex><p class="text-dropdown">Call</p></div>
</div>
<div class="page-holder page-border " horizontal layout center center-justified>
<div>
<core-icon class="dropdown-icon collapsed-holder" icon="fa:envelope"></core-icon>
</div>
<div flex><p class="text-dropdown">Send e-mail</p></div>
</div>
<div class="page-holder page-border" horizontal layout center center-justified>
<div>
<core-icon class="dropdown-icon collapsed-holder" icon="fa:mobile"></core-icon>
</div>
<div flex><p class="text-dropdown">Send Msg</p></div>
</div>
</core-collapse>
</div>
</template>
I've tried to trigger function in toggle function , but i don't think it's good idea because firebug console returns null as Icon variable.
IconClick: function(event, detail, sender) {
var Icon= this.getElementsByClassName('down-icon')[0];
Icon.toggle();
},
toggle: function (e, detail, sender) {
this.IconClick();
}
I think the most "polymery" way to achieve what you want to do is by relying on data-binding without any extra code, binding to the opened attribute of the core-collapse element and hiding the icons using the hidden layout attribute with conditional binding.
Minimal sample:
<template>
<core-icon hidden?="{{opened}}" icon="arrow-drop-down" on-click="{{toggle}}"></core-icon>
<core-icon hidden?="{{!opened}}" icon="arrow-drop-up" on-click="{{toggle}}"></core-icon>
<core-collapse id="collapse" opened="{{opened}}"><div>Content</div></core-collapse>
</template>
<script>
Polymer({
toggle: function () {
this.$.collapse.toggle();
}
});
</script>
The reason why this.getElementsByClassName returns nothing is because you are querying the element's light DOM, but your elements are in the shadow DOM, so you would have to use this.shadowRoot.getElementsByClassName instead.
<core-toolbar class="tall" horizontal start-justified layout>
<div class="logo"><img src="assets/logo.png"></div>
<h1 class="bottom">Company name</h1>
</core-toolbar>
In the above code I have horizontal start-justified layout which mean the element within core-toolbar align to left.
Now I want to change the start-justified to center-justified when screen size below 700px. How to do that with core-media-query ?
Can we just wrap the code to <core-media-query> or we have to create a custom element?
if you have a auto-binding template on the index file there is no need to do it in a custom-element. also polymer has the ability to check attributes against a boolean by using the attribute?="{{value}}" syntax. in the case below start-justified?="{{!queryMatches}}" means that if the page is more then 700px in width queryMatches will be false and content will justify left. while center-justified?="{{queryMatches}}" means that if the page is smaller then the 700px in width queryMatches will be true and content will be center-justified
it would look something like
<template is="auto-binding">
<core-media-query query="max-width:700px" queryMatches="{{queryMatches}}"></core-media-query>
<core-toolbar class="tall" horizontal start-justified?="{{!queryMatches}}" center-justified?="{{queryMatches}}" layout>
<div class="logo"><img src="assets/logo.png"></div>
<h1 class="bottom">Company name</h1>
</core-toolbar>
</template>
here is it working http://plnkr.co/edit/VYdFOt89E6RH7fTTlZ5m?p=preview
edited for completeness
I am currently having my first tries with Polymer.
What I have is a custom polymer element nested in a core-animated-pages element on the main page.
The sources are:
index.html
<core-header-panel>
<core-toolbar>
[...]
</core-toolbar>
<core-animated-pages transitions="slide-from-right">
[...]
<section>
<contact-page></contact-page>
</section>
</core-animated-pages>
</core-header-panel>
contact-page.html
<polymer-element name="contact-page">
<template>
[...]
<div layout horizontal start-justified>
<div class="placeholder">
</div>
<div class="contact-box" layout horizontal center-justified flex three>
<div class="form-container" layout vertical>
<h2>Contact</h2>
<paper-input class="additional-dist" floatingLabel label="Name"></paper-input>
<paper-input id="mail" floatingLabel label="Mail"></paper-input>
<div layout horizontal>
<paper-input id="msg" multiline maxRows="4" rows="4" floatingLabel label="Message" flex></paper-input>
</div>
<paper-button label="Submit" on-tap="{{submit}}" self-end></paper-button>
</div>
</div>
</div>
[...]
</template>
[...]
</polymer-element>
The HTML file currently looks like this in Chrome 37.
Now what I'd like to have is that the yellow bar (placeholder) is vertically stretched over the whole viewport, like this.
Unfortunately I can't figure out which polymer layout attributes I have to use to achieve this and in which tags I have to put them. Can anybody help me here?
Edited to incorporate feedback from sjmiles:
Give this a shot:
<body fullbleed layout vertical>
<polymer-element name="x-foo" layout vertical>
<template>
<style>
#header {
background: tomato;
}
#col {
background: yellow;
}
</style>
<div id="header" layout horizontal>
Header
</div>
<div id="main" flex layout horizontal>
<div flex id="col">Col</div>
<div flex layout vertical>
<div>Section 1</div>
<div>Section 2</div>
<div>Section 3</div>
</div>
</div>
</template>
<script>
Polymer({
});
</script>
</polymer-element>
<x-foo flex></x-foo>
</body>
I'm using the fullbleed attribute to set the body to 100vh and telling it to layout its children vertically using flexbox. Then setting x-foo to flex so it fills the screen. Then it's just a matter of getting the right children to flex.
Here's a jsbin to preview.