Javascript Jquery图像加载函数 //在画布中放置图像时调用 函数dropResource(){ var imgIndex=getImageIndexByID(currentDragImageID); var newImgID=resourceData.length; var-newImage; 新图像=$(''); $('#thePage')。追加(新图像); $('imgA'+newImgID).load(函数(){ //获取属性 var imgW=$('#imgA'+newImgID).width();//本机宽度存储此 var imgH=$('#imgA'+newImgID).height();//Native var imgX=$('#imgA'+newImgID).position().left;//相对,向后缩放 var imgY=$('#imgA'+newImgID).position().top; var zindex=getBiggestZindex()+1; //调整本机尺寸以适应当前比例 $('#imgA'+newImgID).width(数学圆整(imgW*currentScale)); $('#imgA'+newImgID).height(数学圆整(imgH*currentScale)); $('#imgA'+newImgID).css(“z-index”,zindex); //添加到数组(dbID、索引、宽度、高度、x、y) resourceData[newImgID]=新数组(0,imgIndex,imgW,imgH,imgX,imgY,zindex); //使img包装器可拖动 makeResourceDrag(newImgID); //将此另存为资源 $.ajax({ url:'artworkAjaxHandler.ashx?type=addResource&uploadID='+currentDragImageID+'&page='+currentPage+'&w='+imgW+'&h='+imgH+'&x='+imgX+'&y='+imgY+&z='+zindex, 成功:功能(数据){ var splitData=data.toString().split(“|”); //成功 如果(拆分数据[0]=“1”){ }否则{ $.fancybox.close(); $.jGrowl(“图像删除时出错!请尝试重新加载页面。”+splitData[1],{sticky:true}); } }, 错误:函数(){ $.jGrowl(错误处理Ajax请求时出错,{sticky:true}); } }); });
加载函数从未调用…我知道我可能执行得不正确,但一旦图像加载完毕,它会自动调整包装器的大小,然后我需要获取尺寸Javascript Jquery图像加载函数 //在画布中放置图像时调用 函数dropResource(){ var imgIndex=getImageIndexByID(currentDragImageID); var newImgID=resourceData.length; var-newImage; 新图像=$(''); $('#thePage')。追加(新图像); $('imgA'+newImgID).load(函数(){ //获取属性 var imgW=$('#imgA'+newImgID).width();//本机宽度存储此 var imgH=$('#imgA'+newImgID).height();//Native var imgX=$('#imgA'+newImgID).position().left;//相对,向后缩放 var imgY=$('#imgA'+newImgID).position().top; var zindex=getBiggestZindex()+1; //调整本机尺寸以适应当前比例 $('#imgA'+newImgID).width(数学圆整(imgW*currentScale)); $('#imgA'+newImgID).height(数学圆整(imgH*currentScale)); $('#imgA'+newImgID).css(“z-index”,zindex); //添加到数组(dbID、索引、宽度、高度、x、y) resourceData[newImgID]=新数组(0,imgIndex,imgW,imgH,imgX,imgY,zindex); //使img包装器可拖动 makeResourceDrag(newImgID); //将此另存为资源 $.ajax({ url:'artworkAjaxHandler.ashx?type=addResource&uploadID='+currentDragImageID+'&page='+currentPage+'&w='+imgW+'&h='+imgH+'&x='+imgX+'&y='+imgY+&z='+zindex, 成功:功能(数据){ var splitData=data.toString().split(“|”); //成功 如果(拆分数据[0]=“1”){ }否则{ $.fancybox.close(); $.jGrowl(“图像删除时出错!请尝试重新加载页面。”+splitData[1],{sticky:true}); } }, 错误:函数(){ $.jGrowl(错误处理Ajax请求时出错,{sticky:true}); } }); });,javascript,jquery,image,load,Javascript,Jquery,Image,Load,加载函数从未调用…我知道我可能执行得不正确,但一旦图像加载完毕,它会自动调整包装器的大小,然后我需要获取尺寸 有人能帮忙吗?您缺少一个哈希: // Called when image is dropped in canvas function dropResource() { var imgIndex = getImageIndexByID(currentDragImageID); var newImgID = resourceData.length; var newI
有人能帮忙吗?您缺少一个哈希:
// Called when image is dropped in canvas
function dropResource() {
var imgIndex = getImageIndexByID(currentDragImageID);
var newImgID = resourceData.length;
var newImage;
newImage = $('<div id="imgD' + newImgID + '" style="display:inline-block;position:absolute;"><img alt="Big" id="imgA' + newImgID + '" src="' + uploadFolder + '/' + imgData[imgIndex][1] + '" /></div>');
$('#thePage').append(newImage);
$('imgA' + newImgID).load(function() {
// Get properties
var imgW = $('#imgA' + newImgID).width(); // Native width store this
var imgH = $('#imgA' + newImgID).height(); // Native
var imgX = $('#imgA' + newImgID).position().left; // Relative, scale back
var imgY = $('#imgA' + newImgID).position().top;
var zindex = getBiggestZindex() + 1;
// Resize native dimensions to fit current scale
$('#imgA' + newImgID).width(Math.round(imgW * currentScale));
$('#imgA' + newImgID).height(Math.round(imgH * currentScale));
$('#imgA' + newImgID).css("z-index", zindex);
// Add to array (dbID, imgarrIndex, width, height, x, y)
resourceData[newImgID] = new Array(0, imgIndex, imgW, imgH, imgX, imgY, zindex);
// Make img wrapper draggable
makeResourceDrag(newImgID);
// Save this as a resource
$.ajax({
url: 'artworkAjaxHandler.ashx?type=addResource&uploadID=' + currentDragImageID + '&page=' + currentPage + '&w=' + imgW + '&h=' + imgH + '&x=' + imgX + '&y=' + imgY + '&z=' + zindex,
success: function(data) {
var splitData = data.toString().split("|");
// Success
if (splitData[0] == "1") {
} else {
$.fancybox.close();
$.jGrowl("<strong>Error during image drop! Try reloading page.</strong><br />" + splitData[1], { sticky: true });
}
},
error: function() {
$.jGrowl("<strong>Error</strong><br />There was an error when processing the Ajax request", { sticky: true });
}
});
});
$('imgA' + newImgID).load(function()
应该是
$('#imgA' + newImgID).load(function()