jquery UI的可拖动性和可伸缩性不起作用

jquery UI draggability and resizability not working

本文关键字:可伸缩性 不起作用 拖动 UI jquery      更新时间:2023-09-26

当我在jsfiddle上使用外部资源时,这个可拖动性代码正在工作。

但是,通过脚本和样式标记包含jquery和jquery ui文件并不能使我的div具有可拖动性和/或可调整大小。

这太烦人了。我已经试了这么久了。

这是我的代码

HTML:

   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" type="text/javascript"></script>
      <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css">
      <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js" type="text/javascript"></script>
  <div id="outer" style="background-color: #3C3C3C; width: 300px; height: 300px;">
           <div id="object1" class="draggable resizable">
           </div>
  </div>

CSS:

  .draggable.resizable
  {
      position: relative; 
      display: -moz-inline-stack;
      display: inline-block;
      vertical-align: top;
      zoom: 1;
      *display: inline;   
      cursor: hand; 
      cursor: pointer;
      border: 1px solid #E0E0E0;
      z-index: 1;
  }

  .ui-resizable-handle  {
      background: #E0E0E0;
      width: 9px;
      height: 9px;
      z-index: 0;
  }

  .ui-resizable-se
  {
      right: -5px;
      bottom: -5px;
  }
  .ui-resizable-ne
  {
      right: -5px;
      bottom: -5px;
  }

  #object1 {
    background-color: yellow;
    position: absolute;
    left: 10px;
    top: 20px;
    width:30px;
    height: 50px;
  }

JS:

  $('.draggable').draggable({
    containment: '#outer'
  });
  $('.resizable').resizable({
      //aspectRatio: true,
        containment:'#outer'
      , handles: 'ne, se, sw, nw'
  });

正如用户R Lam所指出的,如果您在web浏览器中打开控制台,您应该会看到以下错误。

混合内容:位于"的页面https://fiddle.jshell.net/akashdmukherjee/wj41wLcx/1/show/"通过HTTPS加载,但请求了不安全的脚本"http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"。此请求已被阻止;必须通过HTTPS提供内容。(索引):117混合内容:页面位于'https://fiddle.jshell.net/akashdmukherjee/wj41wLcx/1/show/'是通过HTTPS加载的,但请求了不安全的样式表'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css"。此请求已被阻止;必须通过HTTPS提供内容。(索引):1混合内容:位于'的页面https://fiddle.jshell.net/akashdmukherjee/wj41wLcx/1/show/"通过HTTPS加载,但请求了不安全的脚本"http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"。此请求已被阻止;必须通过HTTPS提供内容。(索引):97未捕获引用错误:$未定义

它可以通过替换http://to//来修复

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css">
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js" type="text/javascript"></script>

下面的JS Fiddle工作