首页 > 解决方案 > JQuery 初学者,“可拖动”不拖动

问题描述

我正在尝试制作一个模拟拼字游戏的程序,允许用户拖动瓷砖块来表示点。但是,我遇到了 JQuery 'Draggable' 函数的问题。我认为这可能与我导入 JQuery 的方式有关,但我正在努力寻找一种方法来测试它。

(另外,如果我的问题的格式不正确,我们深表歉意。第一次使用!)

索引.html

<head>
<meta charset="utf-8">
<link href="css/style.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial scale=1.0">
<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"> 
</script>
<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"> 
</script>
<script type="js/draggable.js"></script>
<title>Scrabble - Nicholas W</title>
</head>

<!-- Some additional irrelevant code here -->

<body>
<div id=pieces class="draggable ui-widget-content">
<p>Piece1</p>
<p>Piece2</p>
<p>Piece3</p>
</div>
</body>

可拖动的.js

$( function() {
console.log("Trying to drag...")
$( ".draggable" ).draggable();
} );

标签: javascriptjqueryhtml

解决方案


您正在寻找的确切功能可以在这里找到:https ://jqueryui.com/draggable/#snap-to

查看最后两个与网格对齐的框


推荐阅读