I'm currently implementing a click function with fade in effects, the only problem is if you don't click straight away the content has already faded away as it started fading when the page was loaded.
Here's my code:
$(document).ready(function(){
$('#slide-02').hide();
$('#button').click(function(){
$('#slide-02').fadeIn(1000);
$('#slide-01').hide();
});
var charToReplace = ['s', 'b', 'S', 'B'];
$('#slide-02').html(function (i, v) {
var resultStr = '';
for (var i = 0; i < v.length; i++ ) {
var ch = v.charAt(i);
if ($.inArray(ch, charToReplace) >= 0) {
resultStr += '<span class="hideMe">' + ch + '</span>';
} else {
resultStr += ch;
}
}
return resultStr;
}).find('.hideMe').delay(2000).fadeOut(3000, function(){
$(this).css('opacity', 0).show();
});
//lets bring it all back
setTimeout(function () {
$('#slide-02').find('.hideMe').css('opacity', 0);
}, 5000);
});
Here's a live mock-up of the code in action too: http://nealfletcher.co.uk/fish/test2/
So #slide-02
is hidden and when #button is clicked #slide-02
fades in, the letters 's' and 'b' fade out of #slide-02
but I only want these letters to start fading once #slide-02
is visible and not start fading when the page is loaded, because currently if you don't click the button straight away, the letters have already faded.
Is there a way to only implement this call AFTER the click function has been implemented?
I will then be adding more slides, one after the other, so I'd like this call to work numerous times if that's possible?