I'm writing an Ionic 2 app and want to use the Slider component (based on Swiper) to do something similar to this demo: http://idangero.us/swiper/demos/28-parallax.html
But whenever I add a parallax item it moves based on the total slider progress (like the background in the demo) and I found no way to have them move based on a single slide progress (like the text in the demo). (Swiper docs)
Does anyone know if that's possible? The Ionic docs don't have any details on parallax in slides.
What I tried:
<ion-slides parallax progress>
<ion-slide>
<h2>No Parallax</h2>
<p data-swiper-parallax="-100">Parallax: -100</p>
<p data-swiper-parallax="-200">Parallax: -200</p>
</ion-slide>
<ion-slide>
<h2>No Parallax</h2>
<p data-swiper-parallax="-100">Parallax: -100</p>
<p data-swiper-parallax="-200">Parallax: -200</p>
</ion-slide>
<ion-slide>
<h2>No Parallax</h2>
<p data-swiper-parallax="-100">Parallax: -100</p>
<p data-swiper-parallax="-200">Parallax: -200</p>
</ion-slide>
</ion-slides>
Demo: http://plnkr.co/edit/k0b92hqkdeUR57t71RR4?p=preview
You can achieve this by putting your background image to be parallaxed in the first slide, like this:
<ion-slides parallax pager>
<ion-slide>
<div class="image-parallax">
<img data-swiper-parallax="2100" src="url.to/image.png"/>
</div>
</ion-slide>
<ion-slide>
<p> Other slide content </p>
<ion-slide>
</ion-slides>
And then, style the div as this:
.image-parallax{
position: absolute;
img{
margin-left: 200px;
width: 2000px;
height: auto;
}
}
And then adjust the margins, width and height of the background.
Hope it helps!
I have managed to solve this with ionic 4, putting the background image in and making the background-attachment local.
my.page.html:
<ion-slides [options]="slideOpts" class="parallax-bg" data-swiper-parallax-x="-20%" [ngStyle]="{'background-image':'url(assets/images/background_'+category+'.svg)'}">
my.page.scss:
.parallax-bg {
background-position: center;
background-attachment: local;
background-repeat: repeat-x;
}
Related
i'd like to add an image as an icon to a navigation button in the header. is this possible? how should i go about it? here is my current code.. it doesnt work:
in the html code:
<ion-nav-bar class="bar-positive custom-dark">
<ion-nav-buttons side="left">
<button class="button" style="background: #1e1e1c;" ng-click="doSomething()">
<i class="icon home"></i>
</button>
in the css code:
.home
{
background: #1e1e1c;
background-repeat: no-repeat;
background-position: left top;
background-size: contain;
background-image: url('img/finalimages/home.png');
display: inline;
}
You could create a custom icon which can be put as your default back button alternative in ionic.
By doing this way you are getting a number of custom icons which can be used throughout your project.
This can be made by following this tutorial:here
On the top of the page, I’ve got a div for which background image has been set. I want to place the fab button on the bottom right edge of this div. Exactly like the following image. How can I do this?
Just use the edge attribute that comes along with fabs:
<ion-fab bottom right edge>
<button ion-fab><ion-icon name="camera"></ion-icon></button>
</ion-fab>
For this to work the div (or any tag) having the fab inside must have position set to relative, absolute or fixed to work, position: inherit may work too depending on parent positioning.
Hope this helps.
Thanks to #Garrett and #Gabriel, I got it working using the following markup and scss. It's important to place the FAB button inside the div to which we want to assign the background image so that we can use relative positioning:
<ion-content>
<div id="header">
<ion-fab bottom right edge>
<button ion-fab><ion-icon name="camera"></ion-icon></button>
</ion-fab>
</div>
</ion-content>
And the scss file:
#header {
background-image: url('../assets/images/anonymous.jpg')!important;
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
height: 25vh;
}
ion-fab {
position: relative;
}
ion-fab[bottom][edge] {
bottom: -21vh;
}
.fab {
margin-right: 3vw;
}
Here is what I could get to work.
This works by creating a fab-container that is going to overlay the main container on this page. For this to work you need to know their heights. Then we make the fab-container z-index of 1 to be on top. Then we can use flex to make the fab be in the bottom right. Then we can add a margin-top half the size of the fab to the fab-container to have the fab hover halfway in-between. Lastly we can add margin-right to get the fab off the right side.
This may not be the best way to do it, since it requires knowing the height of your container, but it was the way that I would approach this task.
<ion-content>
<div class="container"></div>
<div class="fab-conatainer">
<ion-fab class="fab">
<button ion-fab>
<ion-icon name="camera"></ion-icon>
</button>
</ion-fab>
</div>
<div class="contacts-container">
<ion-list>
<ion-item>
<ion-input placeholder="Name"></ion-input>
</ion-item>
<ion-item>
<ion-input placeholder="Phone"></ion-input>
</ion-item>
<ion-item>
<ion-input placeholder="Email"></ion-input>
</ion-item>
</ion-list>
</div>
</ion-content>
CSS
.container {
width: 100%;
background: #333;
height: 500px;
}
.fab-conatainer {
display: flex;
justify-content: flex-end;
align-items: flex-end;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 500px;
z-index: 1;
margin-top: 28px;
}
.fab {
margin-right: 14px;
}
Is there a way to achieve multiline ellipsis text in ionic 2. I have a card view and need to restrict maximum 2 lines to be showed inside it with vertical center alignment. I tried webkit css option but it is not working. I saw similar questions asked by others but couldn't figure out an answer for it.
Below is my html code
<ion-content class="cards-bg light-gray">
<ion-list>
<ion-card *ngFor="let od of orderDetails” class="fade_logo">
<ion-card-content> {{od.description}} </ion-card-content>
</ion-card>
</ion-list>
</ion-content>
Here the order description is long text, I just need to show only 2 lines.
It depends on font size and line height but put this in your .scss file and also change the height: to get the best result.
ion-card-content {
display: block;
display: -webkit-box;
height: 60px;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
In the Ionic app, I need to change the background color for my side menu to become red . By default , when I click or press on one item stable color become the background color but I need to become red .
see this
You can use sass to build your own custumized ionic.css
You can give custom css to set the background color like <ion-content class="dark">
Css
.dark {
background-color: red !important;
color: #ffffff;
}
Sample HTML
<ion-side-menu side="left">
<ion-header-bar class="bar bar-dark">
<h1 class="title">Left Menu</h1>
</ion-header-bar>
<ion-content class="dark">
<ion-list class="list">
<ion-item href="#/event/check-in">Check-in</ion-item>
<ion-item href="#/event/attendees">Attendees</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
You can check the full code/demo on the codpen which have proper comments also : http://codepen.io/mhartington/pen/qafgv
For the other reference you can check this also : http://pointdeveloper.com/ionic-change-side-menu-color/
Try overriding item.active.item-stable and item.activated.item-stable styles in your custom CSS.
Add below styles in your custom CSS:
.item.active.item-stable, .item.activated.item-stable, .item-complex.active .item-content.item-stable, .item-complex.activated .item-content.item-stable, .item .item-content.active.item-stable, .item .item-content.activated.item-stable{
border-color: #B81D22;
background-color: #B81D22;
}
I'm trying to align text in Html but it doesn't work and I do not know why. I'm using Ionic Framework.
My code is:
<ion-list>
<ion-item>
<b>Name</b> <p align="right"> {{paciente.name}}</p>
</ion-item>
....
</ion-list>
and it looks like this:
but I want all text int the same line, and I do not know how to get that.
See this demo: http://play.ionic.io/app/b477ea2f5623
In ionic items, if you write any text within span with item-note class then it will be aligned to right.This is built in class by ionic, your code will be like this :
<ion-item>
<b>Name</b> <span class="item-note"> {{paciente.name}}</span>
</ion-item>
See more tricks with ionic items provide by built in classes, see this Documentation
Add a css class as
.item {
position: absolute;
right: 0px;
width: 300px;
padding: 10px;
}
The p tag creates a paragraph on a new line, so you need an other element. You could use a span element which is floated right:
Html:
<ion-list>
<ion-item>
<b>Name</b> <span class="right"> {{paciente.name}}</span>
</ion-item>
....
</ion-list>
Css:
.right {
float: right;
}
Apply the ckass to all items you want to be on the right.