繁体   English   中英

jQuery图像加载功能

[英]Jquery image load function

// 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() 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM