I am using ion-img inside a virtualScroll element.
The image is HD resolution and I want to scale it down for device widths. I thought ion-img took care of this with its CSS properties, but it does not.
So, setting no width or height on the ion-img means I get a 20x20 grey square.
Setting a width and height of 1920x1080 means I get a huge image on most devices that goes way off screen.
How can I set this to be responsive? I want it to scale with the screen. I can easily do this with a standard img by setting width to 100%.
Below is my code:
<ion-header>
<ion-navbar>
<ion-title>{{ selectedCategory.name }}</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-list [virtualScroll]="selectedCategory.videos" approxItemHeight="300px" approxItemWidth="100%">
<ion-item class="class" *virtualItem="let item; let i=index" padding>
<div *ngIf="item.available != true; then locked; else unlocked"></div>
<ng-template #unlocked>
<div class="video">
<ion-img [src]="item.poster_image_s3" (click)="play(item.video_s3)"></ion-img>
</div> <!-- .video -->
<p class="title"
(click)="play(item.video_s3)"
[ngStyle]="{'color': '#' + selectedCategory.color_hex_code }">
<svg-icon src="assets/img/icons/play-button.svg"
[ngStyle]="{
'fill': '#' + selectedCategory.color_hex_code
}"></svg-icon>
Watch Demo
</p>
<p class="subtitle">{{ item.name }}</p>
</ng-template> <!-- #unlocked -->
<ng-template #locked>
<div class="video">
<div class="locked">
<img src="assets/img/icons/studio-locked.svg" alt="Locked" class="icon">
</div> <!-- .locked -->
<ion-img [src]="item.poster_image_s3"></ion-img>
</div> <!-- .video -->
<p class="title">
Subscribe to Watch
</p>
<p class="subtitle">{{ item.name }}</p>
</ng-template> <!-- #locked -->
</ion-item> <!-- .class -->
</ion-list>
</ion-content>
Related
I want to make mat-card to be clickable and when I hover over the mat-card I wanted to show link cursor. There are many cards when I click on one of the cards I want to navigate to another page. How Can I achieve this?
Is it appropriate to use the following code in my template html.
<a mat-card routerLink= ...> Buy </a>
My first attempt was
<div fxLayout="row rap">
<mat-card>
<mat-card-content>
<div> $100 </div>
<div> 3000 ETB</div>
</mat-card-content>
</mat-card>
<mat-card> .... </mat-card>
</div>
<a *ngFor="let card of childCards" [routerLink]="[card?.targetUrl]">
Write mat card code inside anchor tag.
Why not wrap the mat-card in a <a> but sure to remove the underline styling on it
relevant HTML:
<a class='removeStyle' href='#'>
<mat-card class="example-card">
....
</mat-card>
</a>
relevant CSS:
.removeStyle{
text-decoration: none;
}
complete working stackblitz here
HTML
<mat-card (click)="redirect(100)">
<mat-card-content>
<div> $100 </div>
<div> 3000 ETB</div>
</mat-card-content>
</mat-card>
<mat-card (click)="redirect(200)">
<mat-card-content>
<div> $200 </div>
<div> 4000 ETB</div>
</mat-card-content>
</mat-card>
CSS
mat-card {
cursor: pointer;
margin-bottom: 1rem;
}
TS
redirect(id) {
alert('Called from ' + id);
}
Working Solution : https://stackblitz.com/edit/angular-zr3tqo
I want to create the same design like chrome settings page
https://www.pcworld.com/article/3162716/software/how-to-switch-to-chromes-material-design-settings-page-for-an-easier-experience.html
I do not manage to put the md-switch at the right and in static position like chrome settings
I do manage to put the md-switch in right to the title but I need it always in the middle of the card stick to right.
Image of my result: (current design)
<md-card md-theme="{{ showDarkTheme ? 'dark-purple' : 'default' }}" md-theme-watch>
<div class="option-item">
<div class="option-item-header">
<div class="option-item-header-title">
title
</div>
</div>
<div class="clear"></div>
<div class="option-body">
<p>text</p>
</div>
</div>
<div class="option-switch">
<md-switch ng-model="vm.model" aria-label="active" ng-change="function()">
</md-switch>
</div>
</md-card>
I have created ionic project from cli. Ionic version is 3. I am trying to make title image in center. Somebody please help me
<ion-menu [content]="content">
<ion-header>
<ion-toolbar color='primary'>
<ion-title>
<img src="assets/imgs/logo.png" width="128" />
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
</ion-content>
</ion-menu>
<!-- Disable swipe-to-go-back because it's poor UX to combine STGB with side menus -->
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
you can use ionic CSS utilities to align center
<ion-title text-center>
<img src="assets/imgs/logo.png" width="128" />
</ion-title>
Read More about css utilities
https://ionicframework.com/docs/theming/css-utilities/
When you want to center an element, add the text-align: center property to its parent element.
In your case, you need to change the code to:
<ion-title style="text-align: center">
<img src="assets/imgs/logo.png" width="128" />
</ion-title>
At the first picture everything is ok.
But if i make the width of my browser a little bigger, the result is the following:
Each md-card overlaps the next one and adds overflow-y. This issue is only on xs resolutions. Here is my html:
<div ng-view="" flex="" class="ng-scope flex">
<md-content layout-xs="column" layout="row" class="md-padding ng-scope layout-xs-column layout-row">
<div layout="column" layout-gt-xs="row" layout-wrap="" infinite-scroll="ctrl.nextArticles()" infinite-scroll-disabled="ctrl.isBusy || ctrl.isEnd" infinite-scroll-distance="1" class="layout-wrap ng-isolate-scope layout-gt-xs-row layout-column">
<!-- ngRepeat: article in ctrl.articles -->
<div ng-repeat="article in ctrl.articles" class="post ng-scope flex-xs-100 flex-xl-20 flex-sm-50 flex-md-33 flex-lg-25" flex-xs="100" flex-sm="50" flex-md="33" flex-lg="25" flex-xl="20">
<md-card>
<md-card-header>
<md-card-avatar>
<img src="/images/sidenav-icons/Bomb.svg">
</md-card-avatar>
<md-card-header-text>
<span class="md-title ng-binding">FakeTitle147</span>
<span class="md-subhead ng-binding">FakeRubric3</span>
</md-card-header-text>
</md-card-header>
<img ng-src="/images/test-img.jpg" alt="*ALT*" class="md-card-image" src="/images/test-img.jpg">
<md-card-title>
<md-card-title-text>
<span class="md-headline">Card header</span>
</md-card-title-text>
</md-card-title>
<md-card-content>
<p>
The titles
</p>
</md-card-content>
<button class="md-button md-ink-ripple" type="button" ng-transclude="" ng-click="ctrl.showArticle(article._id)" aria-label="Button">
<span class="ng-scope">Button</span>
</button>
</md-card>
I have no custom css (only background-color). Thanks for your ideas.
The problem was in layout="column". I just replaced this:
<div layout="column" layout-gt-xs="row" layout-wrap="" ...
to this:
<div layout="row" layout-wrap="" ...
This solution is OK for me.
the parent page:
<ion-view view-title="my account" >
<ion-nav-bar class="bar-assertive" align-title="center" ></ion-nav-bar>
<ion-content >
<ion-list>
<ion-item>
<ion-item class="item-remove-animate item-icon-left item-icon-right" type="item-text-wrap" ui-sref="tab.modipass">
<i class="icon ion-ios-unlocked-outline"></i>
<div>company profile</div>
<i class="icon ion-chevron-right icon-accessory"></i>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
the child page:
<ion-view view-title="about company" on-swipe-right="closePage()">
<ion-nav-bar class="bar-assertive" align-title="center">
<ion-nav-buttons side="left">
<button class="button button-clear button-light" ng-click="closePage()">
<i class="ion-ios-arrow-back" style="font-size:20px"></i>
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-content class="padding">
<ul class="list">
<li class="item item-text-wrap item-borderless">about company</li>
</ul>
</ion-content>
</ion-view>
both the parent page and the child page have nav-bar, they have the same assertive color and different title.
when swipe from child back to parent, the child page nav bar becomes blank,no title,no color. the parent page nav bar is normal.
the above situation only happens when swiping.
Please help to check why?
I think it's a bug on Ionic, now I solved it by adding a CSS class
ion-nav-bar.hide {
display: block !important;
}
Remember that is a workaround, follow this issue to tracking the fix.