首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >节总是在调整大小时增长--除非在调试模式下逐步遍历代码。

节总是在调整大小时增长--除非在调试模式下逐步遍历代码。
EN

Stack Overflow用户
提问于 2013-08-04 23:40:26
回答 1查看 37关注 0票数 0

我有一个奇怪的问题,我不能把我的心思放在心上。

我在HTML文档中有一个部分,通过拖动边框来调整大小。

当我拖动左边或底部边框时,一切都很好,并且正确地调整了该部分的大小。

当我拖动顶部或左侧边框时,盒子总是变大。不过,当我调试代码时,请逐行执行。在这种情况下,盒子会随着鼠标的移动而正确地生长或缩小。

我猜事件模型中有一些东西,或者我不完全理解的风格调整。

这只是原型代码,我不使用任何库(只是普通的普通JavaScript)。

代码语言:javascript
复制
// reSizeData is populated by mouse event that start the drag process. It contain the HTMLElement that are resized (node), and which border is being dragged (action)
var reSizeData = {node: null, action: "", inProgress: false}

function reSize(ev){
    ev.stopPropagation();
    var node = reSizeData.node;
    if (node === undefined) return false;
    var borderWidth = styleCoordToInt(getComputedStyle(node).getPropertyValue('border-left-width'));
    // check and set the flag in reSizeData indicating that a resize is in progress.
    // this makes repeated calls to be dropped until current resize event is complete.
    if (reSizeData.inProgress === false) {
        reSizeData.inProgress = true;   
        if (node.getBoundingClientRect) {
            var rect = node.getBoundingClientRect();
            switch (reSizeData.action) {
                case "left" :
                    // this is only working while debugging
                    node.style.width = Math.max(rect.right - ev.clientX, 20) + 'px';
                    node.style.left = ev.clientX + 'px';
                    break;
                case "right" :
                    // this working perfectly
                    node.style.width = Math.max(ev.clientX - rect.left - borderWidth, 20) + 'px';
                    break;
                case "top":
                    // this is only working while debugging
                    node.style.height = Math.max(rect.bottom - ev.clientY, 20) + 'px';
                    node.style.top = ev.clientY + 'px';
                    break;
                case "bottom":
                    // this is working perfectly
                    node.style.height = Math.max(ev.clientY - rect.top - borderWidth, 20) + 'px';
                    break;
            }
            // clear the resize in progress flag
            reSizeData.inProgress = false;
        }
    }
};
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-11 01:40:49

我发现的问题是,我未能翻译鼠标坐标的样式坐标,这是受文档结构影响的。我仍然没有解决的问题是,为什么在Firefox调试器中跨行代码行时,代码工作正常。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18048738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档