I would like to call my callback
after all my transition
end. But I am getting no. of time of callback from each of the transition
end. How to combine all this and make a call back at the end?
Here is my code:
var fadeHandler = function() {
var myCallback = function() {
$.event.trigger('showMenu');
//this is called 6 times
// how to get single time call back after completing all 6 transitions?
}
d3.selectAll('.subAppGroup .subAppPath, .subAppGroup .subAppGroupDetail') //parent group 6 no.s
.transition()
.delay(function(d, i) {
return i * 500;
})
.duration(500)
.style('opacity', 1)
.each("end", myCallback); //this is called 6 times
}
fadeHandler();
I'm not sure if this is the best way to solve it, but it certainly works.
var fadeHandler = function () { var items = d3.selectAll('.subAppGroup .subAppPath, .subAppGroup .subAppGroupDetail'), todo = items.size(); items .transition() .delay(function (d, i) { return i * 500; }) .duration(500) .style('opacity', 1) .each("end", function () { todo--; if (todo === 0) { // $.event.trigger('showMenu'); $("#allDone").fadeIn(); } }); }; fadeHandler();
.subAppGroup * { float: left; width: 50px; height: 50px; opacity: 0.2; margin: 4px; } .subAppPath { background-color: red; } .subAppGroupDetail { background-color: blue; } #allDone { display: none; clear: both; margin: 4px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script> <div class="subAppGroup"> <div class="subAppPath"></div> <div class="subAppGroupDetail"></div> <div class="subAppPath"></div> <div class="subAppGroupDetail"></div> <div class="subAppPath"></div> <div class="subAppGroupDetail"></div> </div> <div id="allDone">All done!</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.