Jquery UI - 可调整大小:也调整大小不准确?
好吧,我没有使用“alsoResize”,但我已经测试过,它的行为是相同的。
当您调整主元素的大小时,底部元素“选取框”的黑色边框通常会与顶部元素的白色虚线边框偏离。
$(".layer").resizable({
//alsoResize: '.marquee',
resize: function(event, ui) {
$('.marquee').css({
width : ui.size.width + "px",
height : ui.size.height + "px",
left : ui.position.left + "px",
top : ui.position.top + "px",
});
},
handles: 'all',
aspectRatio: true,
});
http://jsfiddle.net/digitaloutback/uGr3w/3/
在本地演示中使用 firebug ,到了出线的阶段,可以看到行内元素的left、top和width、height的样式是不同的。
我想知道解决方法是否是将位置和大小统计数据发送到函数,该函数向两个元素输出精确的测量值?还有更简单的选择吗?谢谢
更新:
我有一个可以干净地工作的解决方法..它将可调整大小的计算尺寸传递给一个函数,该函数也将顶层设置为这些尺寸。
我确信有一种更有效的方法可以做到这一点,请随时提供优化版本..
Ok I'm not using the 'alsoResize' but I've tested and it behaves the same.
When you resize the main element, the black border from the bottom element 'marquee' often nudges out of line with the dashed white border from the top element.
$(".layer").resizable({
//alsoResize: '.marquee',
resize: function(event, ui) {
$('.marquee').css({
width : ui.size.width + "px",
height : ui.size.height + "px",
left : ui.position.left + "px",
top : ui.position.top + "px",
});
},
handles: 'all',
aspectRatio: true,
});
http://jsfiddle.net/digitaloutback/uGr3w/3/
Using firebug on a local demo, at the stage they go out of line, you can see the inline element styles for left, top and width, height are different.
I wonder if a work around would be to send the position and size stats to function which outputs an exact measurement to both elements? Any simpler options? Thanks
UPDATE:
I've got a workaround which works cleanly.. it is to pass the resizable-calculated dimensions to a function which sets the top layer to these dimensions also.
I'm sure there's a more efficient method to do this, feel free to offer an optimised version..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ui 参数向调整大小事件报告的大小和位置与实际大小和位置似乎存在差异。这可能是由于构建 ui 参数和触发事件之间存在延迟造成的。
我尝试使用事件运行时报告的实际位置和大小:
这似乎与实际尺寸更匹配。
http://jsfiddle.net/VDfpY/1/
There seems to be a discrepancy in the size and position reported by the ui parameter to the resize event, and the actual sizes and positions. This is possibly due to a delay between the ui parameter being built and the event being fired.
I experimented using the actual position and size reported at the time of the event running:
This seems to match much more precicely the actual dimensions.
http://jsfiddle.net/VDfpY/1/
这个怎么样?
让 CSS 处理大小而不是 JS
http://jsfiddle.net/HerrSerker/uGr3w/5/
--编辑添加的代码
How about this?
Let the CSS handle the sizes and not the JS
http://jsfiddle.net/HerrSerker/uGr3w/5/
--edit added code