I have a component with ngIf directive.
I would that when *ngIf is true render the element but with a delay of 200ms.
<app-kpi1
[ngStyle]="{ transition: 'transform 400ms ease-out', 'transition-delay': '200ms' }"
*ngIf="!isNavExpanded"
></app-kpi1>
I tried with ngStyle but animation is rendered directly without a delay
The property that you want is called an animated delay as in the example below:
div {
animation-delay: 2s;
}
References:
https://www.w3schools.com/cssref/css3_pr_animation-delay.asp
Related
On my page I have 2 divs:
<div class="mycards fight">
<div class="card"><span class="name"></span><div id="att1"><span></span></div><div id="def1"><span></span></div></div>
</div>
<div class="mycards fight2">
<div class="card"><span class="name"></span><div id="att2"><span></span></div><div id="def2"><span></span></div></div>
</div>
I am injecting dome text via jquery like:
$('#att1').html(sometext); $('#att2').html(sometext); etc.
In CSS I set the transition for these elements:
#att1, #att2, #def1, #def2 {
transition: all 1s ease;
}
The problem is, the transition is working only for second DIV, where #att2 and #def2 are present and it ignores it in my first DIV.
I also tried to do it via jquery :
$("#att1").addClass('trans');$("#def1").addClass('trans');
$("#att2").addClass('trans');$("#def2").addClass('trans');
in my script when it is needed, and then in CSS I defined just
.trans {
transition: all 1s ease;
}
but again, it works now only for the first DIV.
For some reason it can't do the same effect for both elemets. Not sure where is the problem.
Example where the transition is expected:
function bonus(val,val1,val2) {
$.ajax
({url: 'bonus.php',
data: {"var1": val,"var2": val1,"var3": val2},
type: 'get',
dataType: 'json',
success: function(datax) {
if (val2===1) {
if (val===1) {$("#att1").addClass('size-50');}
if (val===2) {$("#def1").addClass('size-50');}
if (val===3) {$("#att1").addClass('size-50');$("#def1").addClass('size-50');}
window.setTimeout(function(){
if (val===1) {$("#att1").removeClass('size-50'); $("#att1").addClass('size-30');}
if (val===2) { $("#def1").removeClass('size-50'); $("#def1").addClass('size-30');}
if (val===3) {$("#att1").removeClass('size-50'); $("#att1").addClass('size-30');
$("#def1").removeClass('size-50'); $("#def1").addClass('size-30');}
},500);
}
else {
if (val===1) {$("#att2").addClass('size-50')}
if (val===2) {$("#def2").addClass('size-50');}
if (val===3) {$("#att2").addClass('size-50');$("#def2").addClass('size-50');}
window.setTimeout(function(){
if (val===1) {$("#att2").removeClass('size-50'); $("#att2").addClass('size-30');}
if (val===2) { $("#def2").removeClass('size-50'); $("#def2").addClass('size-30');}
if (val===3) {$("#att2").removeClass('size-50'); $("#att2").addClass('size-30');
$("#def2").removeClass('size-50'); $("#def2").addClass('size-30');}
},500);
}
window.setTimeout(function(){runAll();},1000);
}});
}
Damn, I think the issue was in the conditions I had there using e.g. val===1 which wrongly compared the values. when I replaced it for == now it works for both cases.
Sometimes the core issue is caused by something else...
I want to have a very simple loading effect with a quick opacity change on the whole body. So I use the following CSS
body {
opacity: 0;
transition: opacity 2s;
}
body.show-page {
opacity: 1;
}
and add .show-page on load. Here is the live code http://plnkr.co/edit/Ze5TiqkZYiM41VJZVDuB?p=preview
For some reason it does not transition. After the page is loaded the transition works if I add/remove this class, but when loading, it does not happen. Any idea why?
Your script will run before body has finished loading as the script is inside the body tag.
You maybe want something like this:
function fadeIn() {
var body = document.getElementsByTagName('body')[0];
body.className += 'show-page';
}
window.onload = fadeIn;
Updated Plunker
One workaround can be to slightly delay (50ms) your JS doing so:
setTimeout(function(){body.className += 'show-page';}, 50);
If you look at all the Google apps when you open the side (hamburger) menu the content of the app is greyed.
Here is an example
Is it possible to do this with ion-side-menu in ionic framework? If so, how?
Thank you.
Based on Mark Veenstra's answer, here is the result I came with.
In CSS:
.opaque-content {
opacity: .5;
transition: opacity 300ms ease-in-out;
}
In the controller I'm watching the open ratio of the side menu and set a flag:
$scope.$watch(
function () {
return $ionicSideMenuDelegate.getOpenRatio();
},
function (ratio) {
$scope.sidemenuopened = (ratio == 1);
});
In the template I'm using ng-class to conditionally apply the class:
<ion-side-menus>
<ion-side-menu-content ng-class="{'opaque-content' : sidemenuopened}">
<ion-nav-bar>
</ion-nav-bar>
</ion-side-menu-content>
</ion-side-menus>
This works and makes the page content partially transparent when the side menu is opened.
I believe this is not standard available in Ionic, but if you look at the $ionicModal you can see they do use the same technique there.
If you look at the CSS they use for this option, you should add the following to the correct class:
opacity: .5;
transition: opacity 300ms ease-in-out;
background-color: #000;
You should somehow detect when the side menu is exposed and then apply above CSS to the <ion-nav-view>.
I think you could create a directive or so which watches the $ionicSideMenuDelegate.isOpen() function and based on result apply or remove the CSS.
You only need CSS for this.
When the side menu is opened, there is a CSS class menu-open added to the body tag.
So just add the following and you will get what you want.
body.menu-open ion-side-menu-content {
-webkit-transition: opacity 300ms ease-in-out;
transition: opacity 300ms ease-in-out;
opacity: 0.5;
}
Based on Marius Bancila's answer, here is my solution.
In CSS: nothing
In the controller I'm watching the open ratio of the side menu and set a flag:
$scope.$watch(
function () {
return $ionicSideMenuDelegate.getOpenRatio();
},
function (ratio) {
$scope.sidemenuopened = (ratio == 1);
});
In the template I used modal backdrop background class instead of your opaque-content which isn't gray at all:
<ion-side-menus>
<ion-side-menu-content>
<div ng-class="{'modal-backdrop-bg' : sidemenuopened}"></div>
<ion-nav-bar>
</ion-nav-bar>
</ion-side-menu-content>
</ion-side-menus>
With this you will have the same effect as Google!
Suppose I have toggle function which make animation on height , width and opacity of a div -
transition: width 2s, height 2s , opacity 2s,transform 2s;
Here is its demo - jsFiddle
When it change from hide to show all these 3 attribute got animation ,
Now , I want to apply on it hiding (from show to hide) just animation on its opacity such that it disappear by becoming from opacity : 1 to opacity : 0 (with no height , width change) - like this - jsFiddle .
Update :
I want to make the "show to hide" of the 1st jsFiddle as the "show to hide" of the 2nd jsFiddle without to change the "hide to show" of the 1st hsFiddle .
How to get it ?
You can achieve that by using CSS Transform scale.
You can apply that on your toggle function().
like this:
$('.testDiv').css({
'-webkit-transform': 'scale(1)',
'-moz-transform': 'scale(1)',
'-o-transform': 'scale(1)'
});
and to revert:
$('.testDiv').css({
'-webkit-transform': 'scale(0)',
'-moz-transform': 'scale(0)',
'-o-transform': 'scale(0)'
});
jsFIDDLE DEMO
I am trying to create two buttons, one that will expand a div and one that will collapse it. I've tried to modify this code, but I cant seem to get it to work. I think I just dont understand how to not toggle a link.
I am also trying to make the DIV appear when the page loads. I'm not even sure if this is possible with the way I am writing the code.
Can anyone help me understand what I need to do to get this to work.
http://jsfiddle.net/XUjAH/93/
I am trying to avoid using .slideUp/.slideDown it seems to be interfering with another plugin I am using on the page.
$('#click-meopen').click(function() {
var height = $("#this").height();
if( height > 0 ) {
$('#this').css('height','0');
} else {
$("#this").css({'position':'absolute','visibility':'hidden','height':'auto'});
var newHeight = $("#this").height();
$("#this").css({'position':'static','visibility':'visible','height':'0'});
$('#this').css('height',newHeight + 'px');
}
});
$('#click-meclose').click(function() {
var height = $("#this").height();
if( height > 0 ) {
$('#this').css('height','0');
} else {
$("#this").css({'position':'absolute','visibility':'hidden','height':'auto'});
var newHeight = $("#this").height();
$("#this").css({'position':'static','visibility':'visible','height':'0'});
$('#this').css('height',newHeight + 'px');
}
});
All following text is just IMHO :)
See my exmple here - http://jsfiddle.net/XUjAH/99/
html:
<p id="click-meopen">click me to open</p>
<p id="click-meclose">click me to close</p>
<div id="this">
<div id="content">here<br />is<br />a<br />bunch<br />of<br />content<br />sdf</div>
</div>
as for JS:
$('#click-meopen').click(function() {
$("#this").height($("#content").height());
});
$('#click-meopen').click();
$('#click-meclose').click(function() {
$("#this").height('0');
});
as for CSS it should be the same you have.
UPD: Seems that animation is a bit flaky - when you set 'height: auto' - div is visible from the beginning, however close button ignores animation on first click(I have Chrome with latest update) so I've added some workaround. Also added other styles to support this animation for other browsers like Firefox and Opera and not only for those who support -webkit.
http://jsfiddle.net/XUjAH/110/
in CSS added class and removed 'transition' from the main style:
.with-animation {
-webkit-transition: height 1s ease-in-out;
-moz-transition: height 1s ease-in-out;
-o-transition: height 1s ease-in-out;
transition: height 1s ease-in-out;
}
In JS:
// However our div already have proper size this line
// prevents instantaneous close on first click, don't know why
$("#container").height($("#content").height());
$('#click-meopen').click(function() {
$("#container").height($("#content").height());
});
$('#click-meclose').click(function() {
// If we add class with-animation on upper level div will
// start animation on page load
$("#container").height('0').addClass("with-animation");
});
If you can use toggle then all you need is $("#this").toggle('slow');, but you must replace height: 0; with display: none;
$('#click-meopen').click(function() {
$('#this').show();
});
$('#click-meclose').click(function() {
$('#this').hide();
});
http://jsfiddle.net/XUjAH/95/
Or with toggle
$('#click-meopen').click(function() {
$('#this').toggle();
});
http://jsfiddle.net/XUjAH/96/
You are trying to change this to buttons ?
<input type="submit" id="click-meopen" value="open"></input>
<input type="submit" id="click-meclose" value="close"></input>
<div id="this">here<br />is<br />a<br />bunch<br />of<br />content<br />sdf</div>
That's not hard to do.
I would also recommend you to use .toggle() or the .show(),.hide() methods of jQuery. Just setting the css height property to zero is not a good practice.
Do you want to show the div when the page is loading or when its finished loading ( the DOM is ready) ?
Your JavaScript code would be:
$('#click-meopen').click(function() {
$('#this').show(); // or .toggle()
});
$('#click-meclose').click(function() {
$('#this').hide(); // or .toggle()
});
If you would use only one button you should use the .toggle() method, otherwise stick with the .show(),.hide() method !
When the DOM is ready ( The Page is loaded completely):
$(document).ready(function(){
$('#this').show();
});
documentation of the methods that are used:
http://api.jquery.com/show/
http://api.jquery.com/hide/
http://api.jquery.com/toggle-event/
http://api.jquery.com/ready/
I see that you have used -webkit-transition which works for me in chrome but i guess you want it to work in other browses than webkit.
There are two ways i can suggest, one is to just simply add -moz-transition: height 1s ease-in-out; and transition: height 1s ease-in-out; to do it with css3 but that wont help in older ie browsers.
An other way is to place a div inside your text in the div you want to collapse:
<div id="this">
<div id="height">
text
text
</div>
</div>
then in your javascript you can get the height of the inner div-element, and in that way you can use animate instead of height: auto.
$('#click-meopen').click(function() {
$('#this').animate({'height': $('#height').height()}, 1000);
});
$('#click-meclose').click(function() {
$('#this').animate({'height': 0}, 1000);
});
that should be enough for you.
$('#click-meopen').click(function() {
$("#this").css({'position':'absolute','visibility':'hidden','height':'auto'});
var newHeight = $("#this").height();
$("#this").css({'position':'static','visibility':'visible','height':'0'});
$('#this').css('height',newHeight + 'px');
});
$('#click-meclose').click(function() {
$('#this').css('height','0');
});
$('#click-meopen').click();
http://jsfiddle.net/XUjAH/100/