【问题标题】:Jquery resizable show size while resizingJquery在调整大小时调整大小显示大小
【发布时间】:2013-03-08 17:00:40
【问题描述】:

我正在构建一个 jquery 项目,人们可以在该项目中在地图上绘图,他们可以将 div 放在地图上,然后他们可以四处移动和调整大小。我想要一个在调整 div 大小时更新 div 的当前宽度/高度的框。目前它可以工作,但它只会在他们完成调整大小后更新,但我希望它在他们调整大小时实时更新。

我当前的代码只有在调整大小后才会更新:

$(item).resizable({
            grid: Math.round(gridStand),
            stop : function(event,ui) {
                endW = Math.round($(this).outerWidth()/gridStand);
                endH = Math.round($(this).outerHeight()/gridStand);
                $(this).attr('w', endW).attr('h', endH)
                $('.standW').html('<h5>Breedte</h5><h4>'+($(item).attr('w')/2)+'</h4><span>meter</span>');
                $('.standH').html('<h5>Diepte</h5><h4>'+($(item).attr('h')/2)+'</h4><span>meter</span>')
                }
            })
            .draggable({
                grid: [ Math.round(gridStand), Math.round(gridStand) ],
                 containment: "#map", 
                 scroll: false,
                 stop : function(event,ui) {
                    endX = Math.round($(this).position().left/gridStand);
                    endY = Math.round($(this).position().top/gridStand);
                    $(this).attr('x', endX).attr('y', endY)
                }
            })

有谁知道如何更改它,以便它在调整大小时更新,而不仅仅是在您完成调整大小时更新?

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    resize 事件在调整大小期间触发,每次调整大小对象的大小发生变化。您将希望使用它而不是 stop,它只会在调整大小完成后触发一次。

    【讨论】:

    • 谢谢,它有效!有点糟糕,因为我之前实际上尝试过调整大小,但我忘了添加它计算的部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    • 2016-06-18
    • 1970-01-01
    • 2012-08-02
    • 2020-04-16
    相关资源
    最近更新 更多