javascript - 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();
} );
解决方案
您正在寻找的确切功能可以在这里找到:https ://jqueryui.com/draggable/#snap-to
查看最后两个与网格对齐的框
推荐阅读
- typescript - puppeteer:表格填好后怎么点击保存按钮?
- xcode - UIDatePicker 渲染在 Xcode 13 (iOS 15) 中正确对齐
- javascript - 如何在使用 javascript 构建的秒表中更改暂停以继续,反之亦然
- c - printf 和 ESP_LOGI 的区别?
- html - CSS背景渐变不完全在背景图片之上
- node.js - HandlebarsJs Nodejs 和 JWT
- reinforcement-learning - LunarLander v2 openai 健身房的直升机停机坪坐标
- javascript - 正确处理长时间运行的请求中的 HTTP 连接生命周期
- django-models - 从模型激活信号以创建目录文件夹
- azure - Canvas 应用程序中的认知服务 - 连接错误