我正在创建一种编辑器,并使用它来放大和缩小。css的作用是将主内容区域WHat缩放设置为用户指定的缩放比例。
当我集成时,我注意到jQUery UI .resizable不再根据鼠标位置来调整大小,而是在内容以100%的比例缩放时鼠标所在的位置。这是由于缩放百分比没有考虑在内,我假设。
JSFiddle:http://jsfiddle.net/qwMkt/
有什么办法可以解决这个问题吗?提前感谢
JS代码:
$(document).ready(function(){
$('.box').resizable({
containment: '#container',
handles: "se",
scroll: true
});
});CSS代码:
#container{
zoom: 50%;
background: #ccc;
width: 500px;
height: 500px;
}
#container .box {width: 100px; height: 100px; border: 1px solid #333}发布于 2014-12-09 23:45:18
我曾遇到过类似的问题,但我想出了这个解决方案,使用鼠标的位置和当前的缩放。
此代码仅支持使用南向和东向句柄调整大小。如果要使用任何其他代码,则需要扩展代码。例如,我还实现了东南句柄的代码。但是,为了给出最低限度的要求,我省略了它:
$('.box').resizable({
...
resize: function(event, ui) {
var $element = ui.element;
// Gets the axis that the user is dragging.
var axis = $element.data('ui-resizable').axis;
// Get the dimensions of the element's bounding box. We can't use
// leftOffset + $element.width() because it doesn't factor in the
// current zoom. Morever, we can't just multiply $element.width()
// by the current zoom to get the zoomed width because it still
// gives the wrong value. So we have to be sneaky and use resizable's
// resizer overlays to get the right and bottom values.
var leftOffset = $element.offset().left;
var topOffset = $element.offset().top;
var rightOffset = $element.children('.ui-resizable-e').offset().left;
var bottomOffset = $element.children('.ui-resizable-s').offset().top;
// We are using the mouse location to calculate the width (during
// a horizontal resize) and the height (during a vertical resize)
// of the element. This is because we need the resize box to keep
// up with the mouse when the user is not at 100% zoom.
var mouseX = event.pageX;
var mouseY = event.pageY;
// Must remove the zoom factor before setting width and height.
var mouseCalculatedWidth = (mouseX - leftOffset) / current_zoom;
var mouseCalculatedHeight = (mouseY - topOffset) / current_zoom;
var offsetWidth = (rightOffset - leftOffset) / current_zoom;
var offsetHeight = (bottomOffset - topOffset) / current_zoom;
// In order to maintain aspect ratio, we manually calculate it.
var aspectRatio = offsetHeight / offsetWidth;
// Resizing using the east handler, set the width of the element.
// If this element maintains its aspect ratio, also set the height.
if (axis == "e") {
$element.width(mouseCalculatedWidth);
if (maintainAspectRatio) {
$element.height(mouseCalculatedWidth * aspectRatio);
}
}
// Resizing using the south handler, set the height of the element.
// If this element maintains its aspect ratio, also set the width.
if (axis == "s") {
$element.height(mouseCalculatedHeight);
if (maintainAspectRatio) {
$element.width(mouseCalculatedHeight / aspectRatio);
}
}
}
...
});// Resizable发布于 2017-07-27 02:37:15
如果我正确理解了您的问题,那么您应该在resizable(..)函数的参数中添加alsoResize: "#container"。
https://stackoverflow.com/questions/17285420
复制相似问题