【发布时间】:2015-09-23 03:18:15
【问题描述】:
我在使用 Html2canvas 渲染时遇到问题,因为我想拍摄图像的多个屏幕截图并按顺序将其发送给选定的联系人,但 Html2canvas 以延迟和不连续的方式渲染图像,这反过来无法将图像发送给相应的选定联系人。下面是我的代码,它运行成功,但是延迟和不连续的输出造成了很多问题。
function printCards(calle, eventID){
var cards = new Array();
var checkboxArray = $("input[name='contactsParty']:checked");
$('#inviteContactName').html($(checkboxArray[0]).parent().prev().children('label').text());
// iterating selected checkboxes for invitation
checkboxArray.each(function(index, value){
// getting name of next contact selected
var name = $(checkboxArray[index+1]).parents().eq(1).find('label').text();
// Getting invitation card
var invitationCard;
$.when(invitationCard = getImage(name)).promise().done(function(){
// saving the printed invitation
cards.push(invitationCard);
});
});
return cards;
}
// printing invitation card with contact name
function getImage(name){
var invitationCard = new Image();
html2canvas($("#invitationData"), {
// logging : true,
onrendered: function(canvas) {
// For image`enter code here`
var ctx=canvas.getContext("2d");
// ctx.webkitImageSmoothingEnabled = false;
// ctx.mozImageSmoothingEnabled = false;
ctx.imageSmoothingEnabled = false;
var convertedImage;
$.when(convertedImage = canvas.toDataURL('image/jpg')).promise().done(function(){
invitationCard.src = convertedImage;
$('#inviteContactName').html(name);
});
// setTimeout(function (){}, 500);
}
});
return invitationCard;
}
【问题讨论】:
-
@Niklas 请看看这个话题......
-
可以在 Question 中包含
html吗? , 创建 stacksn-ps , jsfiddle jsfiddle.net 来演示?尝试在imginvitationCardload事件中将invitationCard作为已解析的 jQuery.Deferred 返回? -
yup 尝试了 evrithing .....使用了 jQuery.Deferred 但仍然延迟 n 无序执行...
-
"yup 尝试了 evrithing.....用了 jQuery.Deferred 但仍然延迟 n 非顺序执行..." 可以创建 stacksn-ps, jsfiddle jsfiddle.net 来演示?
-
@guest271314 使用此代码的模块非常复杂...所以我无法创建小提琴或 stacksn-p .....此代码在Firefox 但在 chrome 中它是不连续的。
标签: jquery delay html2canvas