【发布时间】:2017-10-08 23:17:22
【问题描述】:
如随附的小提琴https://jsfiddle.net/0ws7fws0/5/ 所示,用户可以使用东北和东南位置调整三角形的大小。
下面是正在使用的代码
$(document).ready(function() {
var windowWidth = $("#div1").width();
var windowHeight = $("#div1").height();
$(".triangle").css({
"border-top-width": windowWidth / 2 + 'px '
});
$(".triangle").css({
"transform": "rotate(360deg)"
});
$(".triangle").css({
"border-right": windowWidth + 'px solid lightskyblue'
});
$(".triangle").css({
"border-bottom-width": windowWidth / 2 + 'px '
});
$("#div1").draggable({
containment: ".abcde"
});
});
$("#div1").resizable({
handles: "ne,se",
containment: ".abcde",
minHeight: 40,
minWidth: 40
}, {
start: function(e, ui) {
},
resize: function(e, ui) {
var height = Math.round(ui.size.height);
var width = Math.round(ui.size.width);
$(".triangle").css({
"border-top-width": height / 2 + 'px'
});
$(".triangle").css({
"border-bottom-width": height / 2 + 'px'
});
$(".triangle").css({
"border-right": width + 'px solid lightskyblue'
});
$(".triangle").css({
//"margin-top": height + 'px'
});
$(".triangle").css({
"transform": "rotate(360deg)"
});
},
stop: function(e, ui) {
var height = Math.round(ui.size.height);
var width = Math.round(ui.size.width);
}
});
这里用户可以拉伸三角形,但手柄位置应该固定,这样即使调整大小也不会改变位置,即ne和se手柄可以用来调整大小,但w手柄应该固定(禁用)。我如何达到同样的效果?
【问题讨论】:
-
您是否希望将
w“固定”到框中的特定点?将句柄设置为ne和se不会导致其他句柄出现。听起来您在问当resize发生时如何以特定方式转换三角形。您的目标是允许用户创建非等腰三角形吗?
标签: javascript jquery html css jquery-ui