简体   繁体   English

Jcrop未在加载的图像上初始化

[英]Jcrop not initializing on a loaded image

I'm attempting to use Jcrop to make part of an image selectable, to retrieve particular co-ordinates. 我正在尝试使用Jcrop使图像的一部分可选,以检索特定的坐标。 As it stands, I am loading information relating to an image using Ajax, then creating the image tag in Javascript and feeding the information in. I then call a function which SHOULD initialize Jcrop to make the image selectable. 既然这样,我加载使用Ajax,然后创建JavaScript中的图像标签和喂养中的信息与图像有关的信息。然后我打电话应该初始化Jcrop使图像可选择的功能。 The PHP side is definitely coming back with the correct data, the image is being created with the correct source, and the 'setImg' function is registering that it is being called (the window alert pops up). PHP端肯定是回来用,图像被以正确的源产生正确的数据,和“setImg”功能被注册,这是被称为(窗口警报弹出)。

Essentially, I'm not entirely sure what I'm doing wrong regarding Jcrop. 本质上,我不完全确定我在Jcrop方面做错了什么。 I've followed a couple of tutorials about initializing it, which hasn't really resulted in anything. 我遵循了一些有关初始化的教程,但实际上并没有得到任何结果。 The image remains as default. 该图像保留为默认设置。

About the variables: 'pID' and 'cID' are page and comic IDs of the 'page' image being looked for by the Ajax function, then created in the result. 关于变量:'pID'和'cID'是Ajax函数要查找的“页面”图像的页面和漫画ID,然后在结果中创建。

Javascript: Javascript:

<script>

        function editPage(pID, cID)
        {
            $.ajax({
                url : "editPage.php",
                type : "get",
                data: ({'pageID': pID}),

                async: false,
                success : function(result) 
                {
                    document.getElementById("soloPage").innerHTML="";
                    var getImg = result[0].pageLocation;
                    var out = "<br><p><img name ='" + ('solopgnm' + result[0].pageNum) + "' id='solopgid' src='" + result[0].pageLocation + "' width='95%;' ></p>";

                    document.getElementById("soloPage").innerHTML=out;
                    document.getElementById("editPageTagID").innerHTML=("Currently editing: Page " + result[0].pageNum);

                    $("#divEditComics").hide();
                    $("#divEditPage").show();

                    setImg();

                },
                error: function() 
                {
                    connectionError();
                }
            });


        }

    </script>

    <script>

        function setImg()
        {
            window.alert("Function called.");

            jQuery(window).load(function(){

                jQuery('#solopgid').Jcrop({
                    onChange: showCoords,
                    onSelect: showCoords
                });
            });
        }

    </script>

Any help or pointers in the right direction of study would be appreciated (though I have attempted to follow the documentation to little avail. Apologies if I missed something simple). 在正确的学习方向上提供的任何帮助或指导将不胜感激(尽管我试图按照文档进行操作,但收效甚微。如果我错过了一些简单的内容,我们深表歉意)。

Try removing the 'jQuery(window).load(..' portion inside the setImg function. The window load event has already fired so the encased code wont execute. 尝试删除setImg函数内的'jQuery(window).load(..')部分。窗口加载事件已经触发,因此封装的代码将无法执行。

Its hard to know exactly what you are trying without a complete example but here is a quick and dirty jsfiddle example that may help. 没有完整的示例,很难确切知道您要尝试什么,但是这里有一个快速而肮脏的jsfiddle示例 ,可能会有所帮助。 Based on code provided and a bunch of assumptions. 基于提供的代码和大量假设。

 result = [{ pageLocation: "http://deepliquid.com/Jcrop/demos/demo_files/pool.jpg", pageNum: '2' }]; function editPage() { document.getElementById("soloPage").innerHTML = ""; var getImg = result[0].pageLocation; var out = "<br><p><img name ='" + ('solopgnm' + result[0].pageNum) + "' id='solopgid' src='" + result[0].pageLocation + "' ></p>"; document.getElementById("soloPage").innerHTML = out; setImg(); } function showCoords(c) { $('#output').text(cx + ', ' + cy); } function setImg() { //following load line commented out // jQuery(window).load(function(){ jQuery('#solopgid').Jcrop({ onChange: showCoords, onSelect: showCoords }); // }); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js"></script> <div> <div id="soloPage"></div> <div id="output"></div> <button type="button" onclick="editPage()">Click to Load Image</button> </div> 

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

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