How to responsive image in ionic from different screen size? - angularjs

I am creating an ionic app, in that I need to add a four images in my home page in two row and each row has two images. The images size is 296*296.
I have tried the below code,
index.html
<ion-nav-view class="container" >
</ion-nav-view>
Home.html
<ion-view view-title="HOME">
<ion-content>
<div class="row" >
<div class="col-md-6 " id="img1">
<img src="img/hard.png" class="img-responsive " id="img1" >
</div>
<div class="col-md-6" id="img1">
<img src="img/soft.png" class="img-responsive " id="img1">
</div>
</div>
<div class="row" >
<div class="col-md-6 " id="img1">
<img src="img/welcome.png" class="img-responsive " id="img1" >
</div>
<div class="col-md-6" id="img1">
<img src="img/title.png" class="img-responsive " id="img1">
</div>
</div>
</ion-content>
</ion-view>
CSS
#img1{
width: 100%;
height: auto
}

Your ids for div and img are same i.e img1. Change the id and then try. And make width and height important may be some other css overwrites it. Tell me if this works or not.
#img2{
width: 100% !important;
height: auto !important;
}
<div class="col-md-6 " id="img1">
<img src="img/hard.png" class="img-responsive " id="img2" >
</div>

I also got this issue. This code might help to you
HTML
<div class="list card new-feeds wall-post">
<div class="row">
<div class="col">
<div class="item item-image img4">
<img src="img/hard.png">
</div>
<div class="item item-image img4">
<img src="img/soft.png">
</div>
<div class="item item-image img4">
<img src="img/welcome.png">
</div>
<div class="item item-image img4">
<img src="img/title.png">
</div>
</div>
</div>
</div>
css
.wall-post .img4 {
width: 50%;
float: left;
height: 120px;
}
.img4 > img {
height: 100%;
width: 100%;
object-fit: cover;
}

Related

Angular UI Bootstrap multiple carousel one by one

I am using AngularJS with ui bootstrap module.
1) What I need is my carousel to change its items one by one. I found a code (by other person) but it's only in jQuery.
Codepen code in jQuery
html:
<div class="container">
<h1>Use Bootstrap's carousel to show multiple items per slide.</h1>
<div class="row">
<div class="col-md-12">
<div class="carousel slide multi-item-carousel" id="theCarousel">
<div class="carousel-inner">
<div class="item active">
<div class="col-xs-4"><img src="http://placehold.it/300/f44336/000000" class="img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/300/e91e63/000000" class="img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/300/9c27b0/000000" class="img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/300/673ab7/000000" class="img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/300/4caf50/000000" class="img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/300/8bc34a/000000" class="img-responsive"></div>
</div>
<!-- add more items here -->
<!-- Example item start: -->
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/300/8bc34a/000000" class="img-responsive"></div>
</div>
<!-- Example item end -->
</div>
<a class="left carousel-control" href="#theCarousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a>
<a class="right carousel-control" href="#theCarousel" data-slide="next"><i class="glyphicon glyphicon-chevron-right"></i></a>
</div>
</div>
</div>
</div>
less CSS:
.multi-item-carousel{
.carousel-inner{
> .item{
transition: 500ms ease-in-out left;
}
.active{
&.left{
left:-3%;
}
&.right{
left:3%;
}
}
.next{
left: 3%;
}
.prev{
left: -3%;
}
#media all and (transform-3d), (-webkit-transform-3d) {
> .item{
// use your favourite prefixer here
transition: 500ms ease-in-out left;
transition: 500ms ease-in-out all;
backface-visibility: visible;
transform: none!important;
}
}
}
.carouse-control{
&.left, &.right{
background-image: none;
}
}
}
jQuery
$('.multi-item-carousel .item').each(function(){
var next = $(this).next();
if (!next.length) {
next = $(this).siblings(':first');
}
next.children(':first-child').clone().appendTo($(this));
if (next.next().length>0) {
next.next().children(':first-child').clone().appendTo($(this));
} else {
$(this).siblings(':first').children(':first-child').clone().appendTo($(this));
}
});
2) So I want multiple items change one bye one. How to do this in angularJS? Any ideas or directions?

AngularJS : change panel header background based on click

I have a panel header which I have divided into 2 parts.
when I click on one panel then its background is sky blue and text color is white while other panel background is gray with black text color and clicking on that panel background and text color is changed alternatively.
.prefix_event {
text-align: center;
background: #f2f1f1;
color: #555555;
padding: 10px;
font-size: 12px;
}
.prefix_previous {
text-align: center;
background: #24b6e3;
color: #FFFFFF;
padding: 10px;
font-size: 12px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<div ng-app class="row">
<div class="col-md-12 col-sm-12 col-xs-12 ">
<div class="panel panel-default set_padding_0 set_margin_0">
<div class="panel-heading set_padding_0 set_margin_0 cursor_pointer">
<div class="row set_margin_0">
<div class="col-md-6 col-sm-6 col-xs-12 text-center prefix_previous" ng-click="option='event_exhibitors'" ng-init="option='event_exhibitors'">
Event Exhibitors
</div>
<div class="col-md-6 col-sm-6 col-xs-12 text-center prefix_event" ng-click="option='previous_exhibitors'">
Previous Exhibitors
</div>
</div>
</div>
<div class="panel-body" ng-show="option==='event_exhibitors'">
<div class="row ">
<div class="inner-addon right-addon col-md-12 col-sm-12 col-xs-12">
<input type="text" class="form-control" placeholder="Search" />
<i class="glyphicon glyphicon-search search_icon_color"></i>
</div>
</div>
</div>
<div class="panel-body" ng-show="option==='previous_exhibitors'">
<div class="row ">
<p>Previous Exhibitors</p>
<p>Previous Exhibitors</p>
</div>
</div>
</div>
</div>
</div>
what i want is. when clicking on previous exhibitors panel. the background color and text color of event exhibitors should be given to previous exhibitors and event_exhibitors should get previous exhibitors background and text color. so it will be vice versa CSS on click.
Any help would be great.
Its very simple using the toggle option like this in the
$scope.toggle="false";
Your HTML will be like this
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12 ">
<div class="panel panel-default set_padding_0 set_margin_0">
<div class="panel-heading set_padding_0 set_margin_0 cursor_pointer">
<div class="row set_margin_0">
<div class="col-md-6 col-sm-6 col-xs-12 text-center prefix_previous"
ng-click="toggle = !toggle"
ng-class="{prefix_event : toggle, prefix_previous : !toggle}"
>
Event Exhibitors
</div>
<div class="col-md-6 col-sm-6 col-xs-12 text-center prefix_event"
ng-click="toggle = !toggle"
ng-class="{'prefix_previous' : toggle}"
>
Previous Exhibitors
</div>
</div>
</div>
<div class="panel-body" ng-show="option==='event_exhibitors'">
<div class="row ">
<div class="inner-addon right-addon col-md-12 col-sm-12 col-xs-12">
<input type="text" class="form-control" placeholder="Search" />
<i class="glyphicon glyphicon-search search_icon_color"></i>
</div>
</div>
</div>
<div class="panel-body" ng-show="option==='previous_exhibitors'">
<div class="row ">
<p>Previous Exhibitors</p>
<p>Previous Exhibitors</p>
</div>
</div>
</div>
</div>
</div>
DEMO
UPDATE 1 : Also check the modified plunker in the same link
Change these # Previous Exhibitors
<div class="panel-body" ng-show="!toggle">
Change these # Event Exhibitors
<div class="panel-body" ng-show="toggle">
you can achieve this functionality with simple Jquery.
Change colour of table row onclick
and if you use class="col-xs-12" then it overrides other higher sizes as well and make them 12(col-sm-12,col-md-12,col-lg-12).
http://getbootstrap.com/css/#grid

images of different width and height fitted together in a responsive div

Newbie here, please help :)
I want to have a fully responsive div with images as arranged in snippet.jpg.The problem is that I cannot get the layout to work both in desired position as well as responsiveness.
the image files are located here
https://drive.google.com/folderview?id=0Bz3gVhyJDHHvTE84T2dwSVZKaXc&usp=sharing
The following is the HTML and CSS which I have done
<div class=" container-fluid portfolio-image">
<div class="inner_container1" >
<div class="row ">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<img class="img-responsive " src="images/winter1.png" alt=""/>
</div>
</div>
</div>
<div class="inner_container2" >
<div class="row ">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<img class="img-responsive " src="images/Woman2.png" alt=""/>
</div>
</div>
</div>
<div class="inner_container3">
<div class="row ">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<img class="img-responsive " src="images/adult2.png" alt=""/>
</div>
</div>
<div style="clear:both"></div>
<div class="inner_container4" >
<div class="row ">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<img class="img-responsive " src="images/txt background.png" width="400" alt=""/>
<p> Portfolio</p>
</div>
</div>
</div>
</div>
<div class="inner_container5">
<div class="row ">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<img class="img-responsive " src="images/feet2.png" alt=""/>
</div>
</div>
</div>
</div>
CSS
.portfolio-image{
margin:0 !important;
padding:0!important;
}
.inner_container1 {
float:left;
}
.inner_container2 {
float:right;
}
.inner_container3 {
float:left;
}
.inner_container4 {
float:right;
paddin:0px;
margin:0 auto;
}
.inner_container5 {
float:right;
}
.no-pad{
pading:0;
margin:0;
}
<style>
.fulldiv {
width: 100%;
}
.left {
float: left;
}
.right {
float: right;
}
.float-none {
float:none;
}
.float-inherit {
float: inherit;
}
</style>
<div class="fulldiv">
<img src="~/images/winter1.png" class="img-responsive left" style="width:65%;"/>
<img src="~/images/woman2.png" class="img-responsive right" style="width:35%;" />
<img src="~/images/adult2.png" class="img-responsive left" style="width:35%;" />
<img src="~/images/portfolio.png" class="img-responsive float-none" style="width:30%;" />
<img src="~/images/feet2.png" class="img-responsive float-none" style="width:65%;" />
</div>

How to add headers for an Ionic List?

I have an Ionic list like following:
http://i.imgur.com/V0NBvQ3.png
<ion-content>
<ion-list>
<ion-item ng-repeat="x in names|orderBy:'order_id'">
{{ x.order_id + ', ' + x.table_id+', '+x.name+', '+x.phone+', '+x.address+', '+x.remark+', '+changTimetoString(x.ctime)}}
<button onclick="myFunction()">点击这里</button>
</ion-item>
</ion-list>
</ion-content>
I want to add headers for each column, how can I achieve that? thanks.
You are going to want to use the ion grid rather than a list for this. here is a example from a project I made that does what I think you are trying to do:
<div class="list">
<div style="padding: 0px; margin: 0px;" class="item">
<div class="row" style="background-color:#284f9a !important; color: white !important;">
<div class="col left" >
Driver:
</div>
<div class="col center" ng-click="reverse=!reverse; data.metric = 'MPG'">
MPG
<i class="icon" ng-class="{'ion-arrow-down-b': reverse == true && data.metric == 'MPG', 'ion-arrow-up-b': reverse == false && data.metric == 'MPG'}"></i>
</div>
<div class="col right" ng-click="reverse=!reverse; data.metric = 'Miles'">
Miles
<i class="icon" ng-class="{'ion-arrow-down-b': reverse == true && data.metric == 'Miles', 'ion-arrow-up-b': reverse == false && data.metric == 'Miles'}"></i>
</div>
</div>
<div class="row" ng-repeat="item in leaderboardData | orderBy:data.metric:reverse">
<div class="col left">
{{item.Driver}}
</div>
<div class="col center">
{{item.MPG}}
</div>
<div class="col right">
{{item.Miles}}
</div>
</div>
</div>
Then for the alternating row colors add this css:
.row:nth-child(odd) {
background-color: #CCC;
}
.row:nth-child(even) {
background-color: white;
}
looks like this:
You can use either Ionic Grid System, or you can use Ionic List Dividers.
I think the grid will solve you problem.

Ionic Scrolling issue - Page scroll breaks when using ion-scroll

I am pretty new to Ionic Framework and the entire hybrid platform.
I have developed a very simple application by using too many tutorials over the internet and the application is working perfectly as expected except the home page.
I have an overall page view that has an ion-content and then there are multiple ion-scroll on the page.
The problem is the scrolling doesn't work as the normal native Android/iOS application.
Can anyone help with this?
Attached below is the full code:
<ion-view ng-init="LoadPage()">
<ion-content ng-show="contentloading" scroll="true">
<ion-refresher pulling-text="Pull to refresh" on-refresh="LoadPage()" >
</ion-refresher>
<div class="row-no-padding">
<div class="row row-no-padding row-center" style="padding-left: 5px;">
<div class="col-33 col-center">
<h5 class="latest-news headingStyle" data-fittext data-fittext-max="12px">Latest News</h5>
</div>
<div class="col col-center">
<ion-slide-box does-continue="true" auto-play="true" show-pager="false">
<ion-slide ng-repeat="item in Slides" ng-click="GoToPost({{item.id}})">
<h4 class="{{FontDetails(1)}}" style="margin-left: 5px;word-break: break-all;white-space:nowrap;overflow:hidden; color:#bb1515;font-size:12px;" ng-bind-html="item.title | unsafe"></h4>
</ion-slide>
</ion-slide-box>
</div>
</div>
</div>
<div class="row-no-padding">
<ion-slide-box does-continue="true" auto-play="true" show-pager="false">
<ion-slide ng-repeat="item in Slides" ng-click="GoToPost({{item.id}})">
<div class="row-wrap">
<div class="col" style="background: url({{item.thumbnail_images.medium.url}}) no-repeat center center; -webkit-background-size: cover;-moz-background-size: cover;background-size: cover;min-height: 200px;height:250px;max-height:300px;z-index: 1;">
</div>
<div style="background:black;position:absolute;opacity: 0.5;filter: alpha(opacity=50);height:auto;bottom:0%;width: 100%;overflow:hidden;z-index:2; vertical-align: top;" class="col">
<h4 class="latest-news-add {{FontDetails(1)}}" ng-bind-html="item.title | unsafe"></h4>
</div>
</div>
</ion-slide>
</ion-slide-box>
</div>
<!-- </div>
</div>-->
<div class="row-no-padding">
<div class="row row-no-padding" style="padding: 5px;">
<div class="col col-33 col-center">
<h5 class="latest-news categoryHeading {{FontDetails(1)}}">{{'Gujarat'| translate}}</h5>
</div>
</div>
<div class="row row-no-padding" style="padding: 5px; overflow: auto;white-space: nowrap; overflow-y: scroll; position: relative;">
<div class="col" >
<ion-scroll direction="x" scroll-outside="true" class="wide-as-needed">
<span>
<span class="wrapperhome" ng-repeat="item in gujarat">
<img on-swipe-left="onSwipeLeft()" on-swipe-right="onSwipeRight()" ng-src="{{item.thumbnail_images.medium.url}}" ng-click="GoToPost({{item.id}})" width="150px" height="150px"/>
<div>
<h6 class="{{FontDetails(1, 0)}}" ng-bind-html="item.title | unsafe"></h6>
</div>
</span>
</span>
</ion-scroll>
</div>
<!--<div class="col">-->
</div>
<div class="row row-no-padding" style="padding: 5px;">
<div class="col col-33 col-center">
<h5 class="latest-news categoryHeading {{FontDetails(1)}}">{{'Politics'| translate}}</h5>
</div>
</div>
<div class="row row-no-padding" style="padding: 5px;">
<div class="col">
<ion-scroll direction="x" class="wide-as-needed">
<span>
<span class="wrapperhome" ng-repeat="item in politics">
<img ng-src="{{item.thumbnail_images.medium.url}}" ng-click="GoToPost({{item.id}})" width="150px" height="150px"/>
<div>
<h6 class = "{{FontDetails(1)}}" ng-bind-html="item.title | unsafe"></h6>
</div>
</span>
</span>
</ion-scroll>
</div>
</div>
<div class="row row-no-padding" style="padding: 5px;">
<!-- <div class="col col-34" style="text-align: center;margin-bottom: 10px;background-color: firebrick;vertical-align: middle;text-align: center;color:white;font-family: HouseGothicHG23Text-Bold;font-size:1.30em;">
Technology
</div>-->
<div class="col col-center">
<h5 class="latest-news {{FontDetails(1)}} categoryHeading ">{{'Technology'| translate}}</h5>
</div>
</div>
<div class="row row-no-padding" style="padding: 5px;">
<div class="col">
<ion-scroll direction="x" class="wide-as-needed">
<span>
<span class="wrapperhome" ng-repeat="item in technology">
<img ng-src="{{item.thumbnail_images.medium.url}}" ng-click="GoToPost({{item.id}})" width="150px" height="150px"/>
<div>
<h6 class = "{{FontDetails(1)}}" ng-bind-html="item.title | unsafe"></h6>
</div>
</span>
</span>
</ion-scroll>
</div>
</div>
</div>
<div class="row row-no-padding" style="padding: 5px;">
<div class="col">
<ion-list>
<div ng-repeat="item in FooterItems" ng-if="(item.MenuOption !== 'Home' || item.MenuOption !== 'Favorite')" style="margin-bottom: 10px;">
<ion-item style="border: 0px!important;" class="item-stable item item-icon-left home-item-footer item-icon-right {{FontDetails(1)}}" ng-click="toggleGroup({{item.group}},'{{item.link}}')" ng-class="{active: isGroupShown({{item.group}})}">
<i class="icon"><img src="img/{{item.link}}.png" style="width:20px;height:20px;"/></i>
{{item.MenuOption| unsafe | translate}}
<i ng-class="isGroupShown({{item.group}}) ? 'ion-chevron-down' : 'ion - chevron - right'" class="icon" style="font-size:1em;"></i>
</ion-item>
<ion-item class="item-accordion" ng-show="isGroupShown({{item.group}})" style="padding-left:1px;padding-top:1px!important">
<!-- <div class="row row-no-padding">
<div class="col">
<ion-scroll direction="x" class="wide-as-needed">
<span>
<span class="wrapper"
ng-repeat="categoryitem in item.items">
<img ng-src="{{categoryitem.thumbnail_images.medium.url}}" ng-click="GoToPost({{categoryitem.id}})" width="150px" height="150px"/>
<div>
<h6 class = "{{FontDetails(0)}}" ng-bind-html="categoryitem.title | unsafe"></h6>
</div>
</span>
</span>
</ion-scroll>
</div>
</div>-->
<div class="row row-no-padding" style="padding: 5px;">
<div class="col">
<ion-scroll direction="x" class="wide-as-needed">
<span>
<span class="wrapperhome" ng-repeat="categoryitem in item.items">
<img ng-src="{{categoryitem.thumbnail_images.medium.url}}" ng-click="GoToPost({{categoryitem.id}})" width="150px" height="150px"/>
<div>
<h6 class = "{{FontDetails(1)}}" ng-bind-html="categoryitem.title | unsafe"></h6>
</div>
</span>
</span>
</ion-scroll>
</div>
</div>
</ion-item>
</div>
</ion-list>
</div>
</div>
</ion-content>
You need to make sure you're declaring the height and width of each <div> you're scrolling. From the ion-scroll docs:
Basic usage:
<ion-scroll zooming="true" direction="xy" style="width: 500px; height: 500px">
<div style="width: 5000px; height: 5000px;
background: url('https://upload.wikimedia.org/wikipedia/commons/a/ad/Europe_geological_map-en.jpg') repeat">
</div>
</ion-scroll>
Note that it's important to set the height of the scroll box as well as the height of the inner content to enable scrolling. This makes it possible to have full control over scrollable areas.

Resources