javascript - Dojo win.doc 未定义

标签 javascript dojo

我必须从 Dojo 继承 Mover 类,因为如果我不这样做就会出现图形错误,因此必须更改某个功能。

错误:win.doc未定义

define(["dojo/_base/declare", "dojo/dnd/Mover",  "dojo/_base/event", "dojo/dom-geometry","dojo/window"],function(declare,Mover, event,domGeom,win){
    console.log("myMover");
        return declare([Mover],{
        onFirstMove: function(e){
        // summary:
        //      makes the node absolute; it is meant to be called only once.
        //      relative and absolutely positioned nodes are assumed to use pixel units
        var s = this.node.style, l, t, h = this.host;
        switch(s.position){
            case "relative":
            case "absolute":
                // assume that left and top values are in pixels already
                l = Math.round(parseFloat(s.left)) || 0;
                t = Math.round(parseFloat(s.top)) || 0;
                break;
            default:
                var m = domGeom.getMarginBox(this.node);
                s.position = "absolute";    // enforcing the absolute mode
                // event.pageX/pageY (which we used to generate the initial
                // margin box) includes padding and margin set on the body.
                // However, setting the node's position to absolute and then
                // doing domGeom.marginBox on it *doesn't* take that additional
                // space into account - so we need to subtract the combined
                // padding and margin.  We use getComputedStyle and
                // _getMarginBox/_getContentBox to avoid the extra lookup of
                // the computed style.
                var b = win.doc.body;                           // Firebug is telling me win.doc is undefined
                var bs = domStyle.getComputedStyle(b);
                var bm = domGeom.getMarginBox(b, bs);
                var bc = domGeom.getContentBox(b, bs);
                l = m.l - (bc.l - bm.l);
                t = m.t - (bc.t - bm.t);
                break;
        }
        this.marginBox.l = l - this.marginBox.l;
        this.marginBox.t = t - this.marginBox.t;
        if(h && h.onFirstMove){
            h.onFirstMove(this, e);
        }

        // Disconnect touch.move that call this function
        this.events.shift().remove();
    },
    });

});

谁能告诉我解决办法吗?

问候 九月

最佳答案

dojo/window 模块和 dojo/_base/window 模块之间存在差异。只有 dojo/_base/window 模块具有属性 doc .

例如:

require([ "dojo/_base/window", "dojo/window" ], function(win, win2) {
    var myDoc = win.doc; // Returns current document
    var myDoc2 = win2.doc; // Returns undefined
});

关于javascript - Dojo win.doc 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23781803/

相关文章:

javascript - 如果需要重要的变量和参数,如何使 Angular 应用程序安全?

javascript - 在 href click 上发送 ajax 帖子

javascript - 在服务器上查找相同图像并获取文件位置的最佳策略

javascript - 将图像过滤器应用于 Canvas 图像数据或在 JavaScript 中

javascript - 定位一个dojo dijit.form.DropDownButton的内容?

javascript - 我怎样才能访问 dojox-chart?

javascript - 如何使用 jQuery 在 json 子数组中添加值?

javascript - 如何用Dojo组织异步代码?

javascript - dojo.fadeOut 多个节点?

javascript - 哪个框架(Jquery、Dojo、Raphael)更适合在教育视频游戏中实现 SVG?