It’s hard for me to understand, and I don’t like the “solution”, since it really should not solve my problem.
I have a function that 40% of the time is not fully executed. At first I thought it was due to the fact that I was manipulating the img and iframe elements on the fly, however I did different things to make sure the cache and loading are sorted before they do their job.
In particular, the thing that I did with the newCover
variable was performed only in 60% of cases. In my disappointment, I registered a newCover
at the end of the function to understand why it just didn't appear sometimes.
But it’s bizarre, because I register a variable with the console, I get a 100% chance of success with a function that does what it should.
Why is this?!
You can see that he is working on the third post here: http://syndex.me
Here is the code:
albumCover = function(){ $(".forPhotoset").each(function () { var forPhotoset = $(this); var myFrame = forPhotoset.find("iframe"); myFrame.hide(); myFrame.load(function(){ var newCover = myFrame.contents().find('.photoset').children(':first-child').children(':first-child'); newCover.children(':first-child').remove(); var psPre = newCover.attr("href")+ '?' + (Math.random() * 1); newCover.append("<img src='"+ psPre +"' alt='Cover Page' />"); var psHeight = newCover.find('img'); psHeight.load(function(){ if (psHeight.height()>heightRef){ psHeight.height(heightRef); } }) newCover.detach(); forPhotoset.append(newCover);
source share