javascript - Jquery $(window).load not working as expected when in script referenced from inside an iframe -
i have page iframe. trying load animations iframe. each piece of content html page references javascript/jquery scripts soem sort of animation. example:
content.html
<head> <link rel="stylesheet" type="text/css" href="css/slide.css"> <script src="js/library/big_slide_img.js"></script> </head> <body> <img class="big_slide_img" src="http://25.media.tumblr.com/0ab6f805c5a3591168e2fe2133552054/tumblr_mk52iuvbni1s631nvo1_1280.jpg"> </body>
big_slide_img.js
$(window).load(function() { $("#iframe").contents().find('.big_slide_img').animate({left: '-=521'}, 800,function(){}); });
how loaded
loadslide = function(slide_no) { $.ajax( { url: "http://myurl.com", async: false, jsonpcallback: 'jsoncallback', contenttype: "application/json", type: "get", datatype: "jsonp", data: {"action": "loadall"}, success: function(data) { $('#frame_title').html(data.title); $('#text').html(data.text); $('#iframe').contents().find('html').html(data.animation); }, error: function (event, jqxhr, ajaxsettings, thrownerror) { alert('[event:' + event + '], [jqxhr:' + jqxhr + '], [ajaxsettings:' + ajaxsettings + '], [thrownerror:' + thrownerror + '])'); } }); };
my problem
the animations inconsistent , suspect due $(window).load not waiting should. delay rectifies problems:
$(window).load(function() { $("#iframe").contents().find('.big_slide_img').delay(800).animate({left: '521'}, 800,function(){}); });
how achieve without delay? don't know code in these files, avoid having monitor iframe externally , call specific function when done. hoping/assuming, not referencing right.
many thanks.
jquery not call "load" trigger because page instantiated jquery loaded.
you can load jquery inside iframe , put code in "big_slide_img.js": $(function(){ $("#iframe").contents().find('.big_slide_img').delay(800).animate({left: '521'}, 800,function(){}); });
or may create trigger outside of iframe, e call when iframe loaded.
have many other ways.
Comments
Post a Comment