【发布时间】:2019-04-19 13:53:57
【问题描述】:
以下 Javascript 代码链接到 HTML 文件。 Te 文件显示意外标识符错误。有人可以帮我吗? 我已经使用interactJS 来调整类resize-drag 中的元素大小。 我已经包含了 HTML、CSS 和 Javascript 文件。我只是在尝试实现 Interact.js 网站本身的大小调整示例。
interact('.resize-drag')
.draggable({
onmove: window.dragMoveListener,
modifiers: [
interact.modifiers.restrict({
restriction: 'parent',
elementRect: { top: 0, left: 0, bottom: 1, right: 1 }
})
]
})
.resizable({
// resize from all edges and corners
edges: { left: true, right: true, bottom: true, top: true },
modifiers: [
// keep the edges inside the parent
interact.modifiers.restrictEdges({
outer: 'parent',
endOnly: true,
}),
// minimum size
interact.modifiers.restrictSize({
min: { width: 100, height: 50 },
}),
],
inertia: true
})
.on('resizemove', function (event) {
var target = event.target,
x = (parseFloat(target.getAttribute('data-x')) || 0),
y = (parseFloat(target.getAttribute('data-y')) || 0);
// update the element's style
target.style.width = event.rect.width + 'px';
target.style.height = event.rect.height + 'px';
// translate when resizing from top or left edges
x += event.deltaRect.left;
y += event.deltaRect.top;
target.style.webkitTransform = target.style.transform =
'translate(' + x + 'px,' + y + 'px)';
target.setAttribute('data-x', x);
target.setAttribute('data-y', y);
target.textContent = Math.round(event.rect.width) + '\u00D7' + Math.round(event.rect.height);
});
HTML 文件
<!DOCTYPE html5>
<html>
<head>
<link rel="stylesheet" type="text/css" href="drag.css">
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/interact-js@2.1.0/interact.min.js"></script>
<script type="text/javascript" src = "drag.js"></script>
<title>Drag and drop</title>
</head>
<body>
<div class="resize-container">
<div class="resize-drag">
</div>
</div>
</body>
</html>
CSS 文件:
.resize-drag {
background-color: #29e;
color: white;
font-size: 20px;
font-family: sans-serif;
border-radius: 8px;
padding: 20px;
margin: 30px 20px;
touch-action: none;
width: 120px;
/* This makes things *much* easier */
box-sizing: border-box;
}
.resize-container {
display: inline-block;
width: 100%;
height: 240px;
}
【问题讨论】:
-
您发布的代码不包含语法错误。你用的是什么浏览器?
-
您好,请更准确地说明您的问题,您能否提供出现意外标识符异常的行和您的 html 文件。
-
你是在这个文件之前还是之后链接到
<head>中的jquery? -
以上三个文件我已经全部提供了,你能帮我看看吗?
-
您能否复制并粘贴您在控制台中看到的确切错误?这应该与发生错误的行号一起出现。然后你可以突出显示相应的投掷线。还有,欢迎!很高兴有你加入社区。span>
标签: javascript html interactive