我有一个带有 iframe 的页面。我正在尝试将动画加载到这个 iframe 中。每条内容都是一个 html 页面,其中包含对执行某种动画的 javascript/jquery 脚本的引用。例如:
内容.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(){});
});
它是如何加载的
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 + '])');
}
});
};
我的问题
动画不一致,我怀疑这是由于 $(window).load 没有按预期等待。延迟纠正了我所有的问题:
$(window).load(function()
{
$("#iframe").contents().find('.big_slide_img').delay(800).animate({left: '521'}, 800,function(){});
});
我怎样才能毫不拖延地做到这一点?由于我不知道这些文件中的代码是什么,我想避免在外部监视 iframe 并在完成后调用特定函数。我希望/假设,我只是没有引用正确的东西。
非常感谢。