How to slide up and slide down in AngularJS? - angularjs

I am trying to make a simple toggle example in AngularJS. I am facing one issue I need to show and hide with some animation like slide up and slide down. I have search button on header on click I show search div it is working in my plunker. My issue is to do animation...
Secondly I need to add z-index because it generates new layer. When I click search button "my name " come down when search bar is open. Why?
<ion-view>
<ion-header-bar align-title="" class="bar-positive">
<div class="buttons">
<i style="font-size:25px!important" class="icon-right ion-android-radio-button-off" ng-click="showsearch()"></i>
</div>
<h1 class="title">Title!</h1>
<a class="button icon-right ion-chevron-right button-calm"></a>
</ion-header-bar>
<div class="list list-inset searchclass" ng-show="isdiplay">
<label class="item item-input">
<img src="https://dl.dropboxusercontent.com/s/n2s5u9eifp3y2rz/search_icon.png?dl=0">
<input type="text" placeholder="Search">
</label>
</div>
<ion-contend>
<div style="margin-top:50px">
my name
</div>
</ion-contend>
</ion-view>

When using Angular you still have the opportunity to use plain old CSS transitions. However, there are many ways to animate elements. In my solution here I use ng-class instead of ng-show. I toggle the class active when ever you click on the trigger. Finally the class changes the state of the element which results in the animation you would like to achieve.
You could simply change ng-show to ng-class="{'active':isdiplay}" and add the following CSS:
.searchclass {
border: 1px solid red;
margin: 0 !important;
position: relative;
top: 44px;
z-index: 9999;
-webkit-transition: height .3s ease-in-out;
transition: all .3s ease-in-out;
height: 0;
opacity: 0;
}
.searchclass.active {
height: 49px;
opacity: 1;
}
You can however, as I said before, also use ng-show with the module ngAnimate which needs to be included in one of your own modules. This will enable animations out of the box, so that elements which can be animated get classes such as .ng-hide-remove, .ng-hide-add and .ng-hide-add-active etc. You could then style those classes on your own.
angular.module('ionicApp', ['ionic']).controller('MyController', function($scope) {
$scope.isdiplay = false;
$scope.showsearch = function() {
$scope.isdiplay = !$scope.isdiplay;
}
})
.searchclass {
border: 1px solid red;
margin: 0 !important;
position: relative;
top: 44px;
z-index: 9999;
-webkit-transition: height .3s ease-in-out;
transition: all .3s ease-in-out;
height: 0;
opacity: 0;
}
.searchclass.active {
height: 49px;
opacity: 1;
}
<link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet" />
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
<div ng-app="ionicApp" ng-controller="MyController">
<ion-view>
<ion-header-bar align-title="" class="bar-positive">
<div class="buttons">
<i style="font-size:25px!important" class="icon-right ion-android-radio-button-off" ng-click="showsearch()"></i>
</div>
<h1 class="title">Title!</h1>
<a class="button icon-right ion-chevron-right button-calm"></a>
</ion-header-bar>
<div class="list list-inset searchclass" ng-class="{'active':isdiplay}">
<label class="item item-input">
<img src="https://dl.dropboxusercontent.com/s/n2s5u9eifp3y2rz/search_icon.png?dl=0">
<input type="text" placeholder="Search">
</label>
</div>
<ion-contend>
<div style="margin-top:50px">
my name
</div>
</ion-contend>
</ion-view>
</div>

Related

How to style md-card directive in angular js?

How to style material js component in inline style or my local css file.I have tried using defining class in directive like below code,
<md-card style="width: 20px;">
Why not use flex?
<div layout="row">
<md-card flex="20"></md-card>
</div>
To style the md-card, give a class or id to the md-card tag and apply CSS to it.
Refer to https://codepen.io/narmadamurali02/pen/LYrzwJz
HTML code
<section ng-app="app">
<article ng-controller="MainCtrl">
<div layout="row" layout-align="start start" layout-fill>
<md-card id="preview-table" class="preview-outer-container" style="width: 550px; height: 370px;">
<md-toolbar id="preview-header">
<div>card header
</div>
</md-toolbar>
<md-card-content class="pa-5">
<div>
card body
</div>
<md-card-content />
</md-card>
</div>
</article>
</section>
CSS code
.preview-outer-container {
box-shadow: none;
border: 1px solid #ddd;
}
#preview-header {
background: #000;
border-bottom: 1px solid $border-color;
font-size: 12px;
min-height: 30px;
color: #fff;
height: 25px;
cursor: move;
padding: 10px;
}
JS code
var app = angular.module("app", ["ngMaterial"]);
app.controller("MainCtrl", ctrl);
function ctrl($scope, $element) {}
In the above example, I have removed the box-shadow to md-card and for md-toolbar I have overridden the default color blue to black.
Output:
https://i.stack.imgur.com/fdvfL.png

md-tooltip not working with marquee

I am using md-tooltip in md-button and using marquee to display scrolling label of button. But md-tooltip just shows for a second and then disappears when I move mouse over the md-button. I have noticed that when I remove the marquee code md-tooltip is getting displayed properly. Tried using md-z-index, md-visible as well but no help. All the controls are added in section.
<section layout="row" layout-sm="column" layout-align="center center" layout-wrap>
<div ng-repeat="mybutton in allbuttons">
<md-button class="md-fab">
<div >
<md-tooltip md-direction="top" md-visible="true">{{mybutton.buttontooltip}}</md-tooltip>
<img ng-src={{mybutton.imagesource}} style="width:50px" />
</div>
</md-button>
<div class="buttonLabel">
<marquee scrollamount="1" style="float:left; font-size: 12px; width:70px; color: white; padding-right: 5em">
<div>
{{buttonlabel}}
</div>
</marquee>
</div>
</div>
</section>
my css for class buttonLabel is as below.
.buttonLabel {
background-color: #080808;
color:#EEE5E5;
bottom: 2px;
left: 520px;
margin: 10px;
}
Plucker link is below. If you remove marquee it will work fine.
https://codepen.io/naddy1/pen/eKbGVN
Please let me know if I am doing it the correct way?

AngularJS Transition on click

I am kind of new with angular and I found this way to use ng-click and ng-show to show the div with information in when the user clicks the h3.
The only problem is that it just shows up and I would like is it fades in or slides down to be visible. :)
Is this gonna work or should I do another way??
<div class="col-sm-12">
<div>
<h3 class="no-margin-bottom toggleText" ng-click="showInfoHe = !showInfoHe"><i class="fa fa-plus-circle" aria-hidden="true"></i> Hälsoinformation</h3>
<hr class="no-margin-top hr-line">
</div>
</div>
<div class="col-xs-12 col-md-offset-3 col-md-9 margin-top" style="border: 1px solid purple" ng-show="showInfoHe">
<div class="row cats-attributes">
<p>info</p>
</div>
</div>
You can do this without ngAnimate,
by using css transitions and ngClass
what you want to do on click set a variable to true and then have a class that has opacity:1.
so
<div class="parent-div" ng-click="yourVariable = true">
<div class="child" ng-class={'opacity-class': yourVariable}>
</div>
</div>
and then in the css
.parent-div {
transition: opacity ease-in-out 1s;
}
.parent-div.child {
opacity:0;
}
.opacity-class {
opacity: 1;
}
EDIT:
here is an applied solution to the html structure you provided
<div class="col-sm-12">
<div>
<h3 class="no-margin-bottom toggleText" ng-click="showInfoHe = !showInfoHe"><i class="fa fa-plus-circle" aria-hidden="true"></i> Hälsoinformation</h3>
<hr class="no-margin-top hr-line">
</div>
</div>
<div class="show-info-container">
<div class="col-xs-12 col-md-offset-3 col-md-9 margin-top show-info" style="border: 1px solid purple" ng-class="{'opacity-class':showInfoHe}">
<div class="row cats-attributes">
<p>info</p>
</div>
</div>
</div>
css
.show-info-container {
transition: opacity ease-in-out 1s;
}
.show-info {
opacity:0;
}
.opacity-class {
opacity: 1;
}
notice i added a container div and removed the ng-show

Angular / ngDraggable - parent DIV not scrolling when dragging object within

Using ngDraggable/Angular Material and having problems dragging objects within the parent DIV container.
The DIV style has a defined height and an overflow-y of "scroll", and the data is a list of employees.
I was expecting the DIV tag to scroll as I dragged my object down the list, but the scrolling won't trigger.
Stuck for a solution. Any help would be appreciated. The following code snippet is a stripped down example of my code.
.allEmployeeContainer {
height: 500px;
overflow-y: scroll;
}
.employeeHolder{
display: inline-block;
width:100%;
font-weight: normal;
font-size: 10.5pt;
padding:10px 0px 10px 0px;
margin:0px;
}
<div class="allEmployeeContainer">
<div ng-repeat="employee in someCtrl.employees" style="padding:0px; margin:0px" >
<div class="employeeHolder" layout="row" layout-wrap>
<div style="width:100%; margin-top:10px;" layout="row" layout-wrap>
<div flex="15">
<div class="drag-object" ng-drag="true" ng-drag-data="clip"></div><br />
</div>
<div flex>{{employee.firstName}}</div>
<div flex>{{employee.lastName}}</div>
</div>
</div>
</div>
</div>

Ionic device browser difference

I have my Ionic app all set up, however, it doesn't function like in the browser...for example, the background picture doesn't load. Does anyone know why?
Everything, including the API that app communicates with, is stored locally
Here is the view:
<ion-view title="Login" id="page2" hide-back-button="true" hide-nav-bar="true">
<ion-content overflow-scroll="false" padding="true"
style="background: url('../img/loginBackground.jpg') no-repeat center;background-size:cover;">
<form class="list">
<style scoped>
.inputCustom{
background-color: rgba(255,255,255,0.8);
}
.imgBack{
display: block;
margin-left: auto;
margin-right: auto;
overflow: visible;
min-width: 60vw;
max-height: 60vw;
max-width: 60vw;
}
</style>
<img src="../img/logo.gif" class="imgBack">
<div class="spacer" style="height: 60px;"></div>
<ion-list>
<label class="item item-input inputCustom">
<span class="input-label">E-mail</span>
<input type="email" placeholder="" ng-model="user.email">
</label>
<label class="item item-input inputCustom">
<span class="input-label">Lozinka</span>
<input type="password" placeholder="" ng-model="user.password">
</label>
<div class="animated flash" ng-show="validationBool"
style="text-align: center; padding-top: 5px; color: indianred">{{validationError}}
</div>
</ion-list>
<div class="spacer" style="height: 40px;"></div>
<a ng-click="signIn()" id="login-button1" class="button button-positive button-block">Prijavi se</a>
<a ui-sref="signup" id="login-button2" class="button button-positive button-block button-clear">Nemaš račun? Registriraj se</a>
</form>
</ion-content>
</ion-view>
what I understand here is that you getting problem in showing up images in ionic. So here's the solution.
Problem in your code is here
background: url('../img/loginBackground.jpg')
You haven't gave a proper url for your image.This must be like this.
background: url('/img/loginBackground.jpg')
Note: No dots and your image would be in "www/img".
Same for the img tag.
EDIT:
try this
.scroll-content {
background:url(/img/loginBackground.jpg) no-repeat center;
background-size: cover;
and remove style bavckground from ionic content.
I found out that the preceding slash was causing the problem. The correct path is
<ion-content overflow-scroll="false" padding="true"
style="background: url(img/loginBackground.jpg) no-repeat center;background-size:cover;">
And for logo:
<img src="img/logo.gif" class="imgBack">

Resources