Bootstrap 并没有原生支持拖拽功能,但可以通过使用第三方库来实现。以下是一个基于 jQuery UI 的示例:

  1. 引入 jQuery 和 jQuery UI 库:
<script src='https://code.jquery.com/jquery-3.5.1.min.js'></script>
<script src='https://code.jquery.com/ui/1.12.1/jquery-ui.min.js'></script>
  1. 创建可拖拽的元素:
<div id='draggable' class='ui-widget-content'>
  <p>拖拽我</p>
</div>
  1. 初始化拖拽功能:
$(function() {
  $('#draggable').draggable();
});

完整示例代码:

<!doctype html>
<html lang='en'>
<head>
  <meta charset='UTF-8'>
  <title>Bootstrap 拖拽示例</title>
  <link rel='stylesheet' href='https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css'>
  <style>
    #draggable { width: 150px; height: 150px; padding: 0.5em; }
    #draggable p { margin: 0; }
  </style>
</head>
<body>

<div id='draggable' class='ui-widget-content'>
  <p>拖拽我</p>
</div>

<script src='https://code.jquery.com/jquery-3.5.1.min.js'></script>
<script src='https://code.jquery.com/ui/1.12.1/jquery-ui.min.js'></script>
<script>
  $(function() {
    $('#draggable').draggable();
  });
</script>
</body>
</html>
Bootstrap 拖拽功能实现:使用 jQuery UI

原文地址: https://www.cveoy.top/t/topic/oHxC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录