Am a bit stuck with getting my head around a basic fade-in and fade-out using Angularjs.
I am displaying the results of values I am returning from a database using the ng-if and want to fade in the results and fade it out upon clicking it again, based on whether this condition is met (ng-if="detail.categoryId === expense.categoryId") As I have it now it fades in and then immediately fades out again when clicking on it once.
HTML
<div class="row expenseBreakdown fade" ng-if="detail.categoryId === expense.categoryId" ng-repeat="detail in expensesDetail">
<div class="col-md-3">{{detail.expenseDetail}}</div>
<div class="col-md-3">{{detail.dateExpense|date}}</div>
<div class="col-md-3">{{detail.expenseAmount|currency:"R"}</div>
</div>
CSS
.fade.ng-enter {
transition:0.5s linear all;
opacity:0;
}
/* The finishing CSS styles for the enter animation */
.fade.ng-enter.ng-enter-active {
opacity:1;
}
You have to use ng-if inside ng-repeat like
<div class="row expenseBreakdown fade" ng-repeat="detail in expensesDetail">
<div class="fade ng-enter ng-enter-active" ng-if="detail.categoryId == expense.categoryId">
<div class="col-md-3">{{detail.expenseDetail}}</div>
<div class="col-md-3">{{detail.dateExpense|date}}</div>
<div class="col-md-3">{{detail.expenseAmount|currency:"R"}}</div>
</div>
<div class="fade ng-enter" ng-if="detail.categoryId != expense.categoryId">
<div class="col-md-3">{{detail.expenseDetail}}</div>
<div class="col-md-3">{{detail.dateExpense|date}}</div>
<div class="col-md-3">{{detail.expenseAmount|currency:"R"}}</div>
</div>
</div>
Related
I’ m doing an animation for a website.
My client wants a row with some images.
These images have to translate constantly on load, but when I click in the row, the images must accelerate as an exponential function for 4 seconds: after that, the website must change page.
Yesterday I have created the animation, changing the animation-duration every some millis by an hook, that strategy was working perfectly, but I don’t like that because it seems to be too heavy.
Now I have found another solution that uses only css and an hook to change the class.
Given this new solution, I still have 2 issues:
after the click, the animation restarts
the second part of the animation calculates the delay from the start and not from the first part of animation
Thank you for your reply
const row = document.querySelector(".row");
row.addEventListener("click", () => row.classList.add('row-click'));
.row{
display: flex;
flex-direction:row;
overflow: hidden;
}
.cell{
background:#f00;
color:#fff;
font-size:26px;
min-width:100px;
margin-right:12px;
animation: slide-first-desktop 10s linear infinite;
}
.row-click > .cell{
animation:
slide-first-desktop 5s cubic-bezier(1,0,.74,1),
slide-first-desktop 2s linear infinite;
}
#keyframes slide-first-desktop {
0%{
transform: translateX(0px);
}
100% {
transform: translateX(-1680px);
}
}
<div class="row">
<div class="cell">1</div>
<div class="cell">2</div>
<div class="cell">3</div>
<div class="cell">4</div>
<div class="cell">5</div>
<div class="cell">6</div>
<div class="cell">7</div>
<div class="cell">8</div>
<div class="cell">9</div>
<div class="cell">10</div>
<div class="cell">11</div>
<div class="cell">12</div>
<div class="cell">13</div>
<div class="cell">14</div>
<div class="cell">15</div>
<div class="cell">1</div>
<div class="cell">2</div>
<div class="cell">3</div>
<div class="cell">4</div>
<div class="cell">5</div>
<div class="cell">6</div>
<div class="cell">7</div>
<div class="cell">8</div>
</div>
Instead of relying on the animation-delay to queue the two animations, you can listen to animation events in JavaScript: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/animationstart_event
const animation = document.querySelector('p.animation');
animation.addEventListener('animationstart', () => {
console.log('animation started');
animation.classList.add('animation-running');
// do something
});
animation.addEventListener('animationend', () => {
console.log('animation ended');
animation.classList.remove('animation-running');
// do something
});
In the example, I'm using the events to toggle a animation-running class. You could use this to check if an animation is running and prevent to restart it on click.
Hi I am trying to add a fade effect onto some images on a website I am making, I also want text to appear on the image when you hover over it. I have been googling and found tutorials saying you should use a class=overlay and class=text within a container and then reference to that in the css. I did this but it messed my whole format up and all my pictures moved. Should I add the overlay class into a separate div, if not how do I integrate it into my pre-existing code. Thanks!
<div id="image-wrap">
<div class="image-column" id="col-1">
<div class="image-container"><img src="images/piertopier.jpg.JPG"></div>
<div class="image-container"><img src="images/lookingback.jpg.JPG"></div>
<div class="image-container"><img src="images/heartshapedflocks.jpg.JPG></div>
</div>
<div class="image-column" id="col-2">
<div class="image-container"><img src="images/twilight.jpg.JPG"></div>
<div class="image-container"><img src="images/kindofblue.jpg.JPG"></div>
<div class="image-container"><img src="images/palace.jpg.JPG"></div>
</div>
<div class="image-column" id="col-3">
<div class="image-container"><img src="images/springtide.jpg.JPG"></div>
<div class="image-container"><img src="images/medina.jpg.JPG"></div>
<div class="image-container"><img src="images/stipple.jpg.JPG"></div>
</div>
</div>
In your style sheet section add below style, to produce a hover fade effect
img:hover{opacity:0.5;transition:1ms;}
Change the values of opacity and transition as suited for you
When you hover over the icon images the background color turns black. How do I change this to grey?
<h2>Contact Us Anytime!</h2>
</div>
</div> </div></section>
<section class="container"><div class="row">
<div class="spb_content_element col-sm-6 column_container">
<div class="spb-asset-content">
<section class="container"><div class="row">
<div class="spb_icon_box col-sm-12">
<div class="spb-asset-content">
<div class="sf-icon-box sf-icon-box-left-icon sf-animation sf-icon- " data-animation="none" data-delay="0" style="background-color:;"><div class="sf-icon-cont cont-small sf-icon-float-none"><i class="fa-map-marker sf-icon sf-icon-small" style="color:;"></i></div><div class="sf-icon-box-content-wrap clearfix"><h3 style="color:;"></h3><div class="sf-icon-box-content" style="color:;">
<p> CT</p>
</div></div></div>
</div>
</div> </div></section>
Change:
.sf-hover .sf-icon-cont, .sf-hover .sf-icon-box-hr {
background-color: #222!important;
}
To:
.sf-hover .sf-icon-cont, .sf-hover .sf-icon-box-hr {
background-color: #8C8C8C!important;
}
How to scrutinize CSS like a pro
1) Right click on the HTML element -> Inspect element
2) Right click on the specific DOM -> Force element state -> :hover
3) * Play with the CSS on the right panel at real-time until you are satisfied.
When life gets complicated
Sometimes a sophisticated programmer decides to change the CSS on the fly using Javascript. So the second step won't help. To solve this issue you can hover the desired element and witness the DOM is being changed. I saw the DOM is being fulfilled with the sf-hover class so I added this class manually. That's how I was able to play with the CSS on the right side.
So I am attempting to create a menu element that shows and hides specific divs on a page, while also changing the text of the menu. After a little searching I have it worked out for the most part (although I know the code is a bit kludgey):
$(document).ready(function(){
$('.section[id="option1"]').click(function(){
$(this).text($(this).text() == 'OPTION1' ? 'OPTION1 >>' : 'OPTION1');
$('.blurb').not('.blurb[id="option1"]').hide();
$('.blurb[id="option1"]').slideToggle();
});
$('.section[id="option2"]').click(function(){
$(this).text($(this).text() == 'OPTION2' ? 'OPTION2 >>' : 'OPTION2');
$('.blurb').not('.blurb[id="option2"]').hide();
$('.blurb[id="option2"]').slideToggle();
});
$('.section[id="option3"]').click(function(){
$(this).text($(this).text() == 'OPTION3' ? 'OPTION3 >>' : 'OPTION3');
$('.blurb').not('.blurb[id="option3"]').hide();
$('.blurb[id="option3"]').slideToggle();
});
$('.section[id="option4"]').click(function(){
$(this).text($(this).text() == 'OPTION4' ? 'OPTION4 >>' : 'OPTION4');
$('.blurb').not('.blurb[id="option4"]').hide();
$('.blurb[id="option4"]').slideToggle();
});
$('.section[id="option5"]').click(function(){
$(this).text($(this).text() == 'OPTION5' ? 'OPTION5 >>' : 'OPTION5');
$('.blurb').not('.blurb[id="option5"]').hide();
$('.blurb[id="option5"]').slideToggle();
});
$('.section[id="option6"]').click(function(){
$(this).text($(this).text() == 'OPTION6' ? 'OPTION6 >>' : 'OPTION6');
$('.blurb').not('.blurb[id="option6"]').hide();
$('.blurb[id="option6"]').slideToggle();
});
});
(full code in action can be viewed here)
This code works for the most part, except that if you already have a certain element (class="blurb") shown, when you click on the menu item (class="section") for another element, the menu indicates that the other element is still open. It seems like there must be a simple way to append or remove the desired text on click, but I can't seem to find a good way of doing it. Would it be worth rewriting the code using something like expander.js?
Here is the effected html
<div class="nav">
<div class="section" id="option1">option1</div>
<div class="section" id="option2">option2</div>
<div class="section" id="option3">option3</div>
<div class="section" id="option4">option4</div>
<div class="section" id="option5">option5</div>
<div class="section" id="option6">option6</div>
</div>
<div class="blurb hidden" id="option1">
<h1>content for option1</h1>
</div>
<div class="blurb hidden" id="option2">
<h1>content for option2</h1>
</div>
<div class="blurb hidden" id="option3">
<h1>content for option3</h1>
</div>
<div class="blurb hidden" id="option4">
<h1>content for option4</h1>
</div>
<div class="blurb hidden" id="option5">
<h1>content for option5</h1>
</div>
<div class="blurb hidden" id="option6">
<h1>content for option6</h1>
</div>
I'm still fairly new to jQuery, so any advice/pointers is greatly appreciated.
I solved your problem using a custom class and :after CSS styles: http://jsfiddle.net/mblase75/sDrZ2/3/
First, some CSS to append the arrows and convert to uppercase without modifying the text directly:
.uppercase {
text-transform: uppercase;
}
.uppercase.arrowed:after {
content: " >>";
}
Add in some changes to your HTML to utilize data- attributes, remove duplicate IDs and add an arrowed class which the JS toggles:
<div class="nav">
<div class="section arrowed" data-blurb="option1">option1</div>
<div class="section arrowed" data-blurb="option2">option2</div>
<div class="section arrowed" data-blurb="option3">option3</div>
<div class="section arrowed" data-blurb="option4">option4</div>
<div class="section arrowed" data-blurb="option5">option5</div>
<div class="section arrowed" data-blurb="option6">option6</div>
</div>
And finally, a rewrite to optimize your JavaScript a lot:
$('.section').click(function () {
$(this).addClass('uppercase').toggleClass('arrowed')
.siblings('.section').removeClass('arrowed');
$('#'+$(this).data('blurb')).slideToggle()
.siblings('.blurb').hide();
});
Note that the arrowed class is toggled, so it needs to be added initially so that it's toggled off on the first click.
my first question here so be gentle :).
I have this issue with changing css of elements and their refresh. I am createing a webforms application with ajax requests. My problem is that when somone chooses a report from a tree view it should display a gif with loading sign and after data is recieved it should display it. Its working fine on firefox and opera but not on ie, chore or safari. Here is the code:
This the method that is launched when someone clicks a tree node
this.hideElements();
var id = node.getId().substr(2);
var client = new CAjaxClient();
var data;
client.addParameter(new CKeyValuePair('ReportID', id));
client.postCallBack('/ajaxpages/Reports.aspx', 'GetReportFilters', this.dataRecieved);
filterGenerator.setReportID(id);
This the method hideElements()
$('#FiltersContainer').css('visibility', 'hidden');
$('#ActionsContainer').css('visibility', 'hidden');
$('#loadingDiv').css('visibility', 'visible');
$("input[id$='Date']").parent().css('visibility', 'hidden');
This the ajax postBack method
if (this.readyState == 4 && this.status == 200) {
$('#FiltersContainer').css('visibility', 'visible');
$('#ActionsContainer').css('visibility', 'visible');
$('#loadingDiv').css('visibility', 'hidden');
var data = eval(this.responseText);
filterGenerator.processFiltersData(data);
Data and everything is returned in order its just that in the request time the browser is like frozen and when the data returns css state is of that at the end of the whole process. Loading div is never shown. I tried also forcing redraw with domelement.style changing but no effect. When I execute the code in chrome debugger line by line everything goes perfectly. Please help if you can.
Html code(vio:TreeView is our own ASP control):
<div id="pageHeader" style="display:inline-block">
<div id="headerImageDiv" style="float:left; margin-left:15px; margin-top:5px;">
<img src="style/default/printerLarge.png" alt="" />
</div>
<div id="pageTitleDiv" style="float:left">
<span style="display:block; margin-top:20px;margin-left:10px;color:#78b4bb; font-size:20px;">Reports And Analyses</span>
<span style="display:block; margin-top:20px;margin-left:10px;font-size:18px;">Select a report</span>
</div>
</div>
<br />
<div id="mainPane" style="display:inline-block;width:100%;">
<div id="readerTreeContainer" style="float:left;border-top-style:solid;border-left-style:solid;border-bottom-style:solid;border-right:none; border-width:1px; overflow : auto;width:300px;height:auto; background-color:white;">
<vio:TreeView ID="TreeView" runat="server"
Width="298" Height="500"
ActionListener="ReportsGeneralListener"
ActionListenerScript="ReportsGeneralTree.js"
GlobalTreeviewName="reportsTreeview">
</vio:TreeView>
</div>
<div id="FiltersContainer" style="position:relative;visibility:hidden;float:left;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left:solid 1px; border-width:2px; overflow : auto;width:30%;height:500px; background-color:#dbdae4;">
<div id="filterColumnOne" style="float:left;width:50%;height:100%;border-right:solid 1px;border-left:none;">
</div>
<div id="filterColumnTwo" style="float:left;width:49%;height:100%;">
</div>
<div id="loadingDiv" style="z-index:10;position:absolute;top:50%;left:50%;margin: -35% 0 0 -35%;z-index:100001;height:316px;width:396px;">
<div style="position:relative;display:block">
<img src="style/default/loading.gif" alt="" style="position:absolute;left:0px;top:0px;z-index:-1;"/>
<span style="display:block;text-align:center;padding-top:80px;font-size:25px;font-weight:bold;">Loading Report</span>
</div>
</div>
</div>
<div id="ActionsContainer" style="visibility:hidden;float:left;border-left-style:none;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-width:2px; overflow : auto;width:200px;height:200px; background-color:#abe9e7;">
<div style="display:block;border-bottom:solid 1px;height:50%">
<div style="position:relative; height:100%;">
<div style="position:absolute;top:50%;left:50%; height:72px;margin: -35px 0 0 -35%;">
<img src="style/default/document.png" alt="" style="float:left;margin-right:10px;"/>
<button type="button" style="margin-top:18%;height:30px;" onclick="print();">Print</button>
</div>
</div>
</div>
<div style="display:block;border:none;height:49%;">
<div style="position:relative; height:100%;">
<div style="position:absolute;top:50%;left:50%; height:72px;margin: -35px 0 0 -35%;">
<img src="style/default/application_pdf.png" alt="" style="float:left;margin-right:10px;height:72px;"/>
<button type="button" style="margin-top:18%;height:30px;">PDF</button>
</div>
</div>
</div>
</div>
</div>
Try .hide and .show instead. They work cross-browser.
See the jQuery API
I think your problem was:
<div stuff I'm hiding>
<div loading screen>
See here for a working demo of what you provided. I removed the inline visibility:hidden from the styles (I'd suggest you split into a CSS file, it's making it unreadable) and took the loading div from inside the div you were hiding.