我使用同一元素的两个功能,一个是AJAX保存图片和第二个是prettyPhoto AJAX这里dispaying该图片是例如如何超时href?
这是EVENT
> <a rel="prettyPhoto[ajax]" onClick="return false"
> onMouseDown="javascript:capture();"
> href="xhr_response.php?ajax=true&width=1100&height=482"><img
> src="img/assets/zoom2.png"></a>
在这里,我initalize prettyPhoto
$(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto({ social_tools:false, });
});
这里是我的捕捉功能来保存图像
function capture() {
$('#zoomTarget').html2canvas({
onrendered: function (canvas) {
var url = "ajax.php";
var imgSrc = canvas.toDataURL();
$.post(url, {contentVar: imgSrc } ,function(data) {});
}
});
}
所有工作不错,但问题是,我需要一些时间来保存图像,并prettyPhoto加载图像如此之快,这意味着,适当的图像没有被加载在第一次当用户点击时,元素,需要时间到相同的图像,第二次或第三次适当的图像显示确定,如何preve prettyPhoto等待图像被保存?
这里是保存图像的回调函数ajax.php
$contentVar = $_POST['contentVar'];
$filteredData=substr($contentVar, strpos($contentVar, ",")+1);
//Decode the string
$unencodedData=base64_decode($filteredData);
//Save the image
file_put_contents('img.png', $unencodedData);
也许我可以在捕获初始化prettyPhoto()函数,并且超时前,并在功能结束时禁用prettyPhoto? –
为什么不在“准备回调”函数(数据){}中加载新图像? –
你可以写一个代码吗? –