Functions and callbacks
Functions and callbacks
I have worked out what is wrong with my code - I think I need to be using functions and call backs but I haven't ever done this without using the built in call backs.
I have annotated the code below with the parts that I want to fire in order only after the process before that has happened.
Hope this makes sense. Any help would be much appreciated.
- function fadeBackground(image) {
-
- ///***** WANT TO HAPPEN FIRST**************
-
- var border;
-
-
-
- $.cacheImage(image, {
- load : function (e) {
- $('#wrapper_2 img').attr('src', image);
- border = ($(window).height() - $('#wrapper_2 img').outerHeight())/2;
-
- },
-
- });
-
- ///***** WANT TO HAPPEN SECOND ONLY AFTER FIRST IS COMPLETED**************
-
- $('#wrapper_2 img').css("margin-top", border);
- $('#wrapper_2').css('background-color', $backgroundcolour);
-
-
- ///***** WANT TO HAPPEN THIRD ONLY AFTER SECOND IS COMPLETED**************
- $('#wrapper_2').fadeIn('slow', function() {
- $('#wrapper_1').css( 'background-color', $backgroundcolour);
- $('#wrapper_1 img').attr('src', image);
- $('#wrapper_2').css('display', 'none');
- $('#wrapper_1').css('display', 'block');
- $('#wrapper_1 img').css("margin-top", border);
- });
-
- }