简体   繁体   English

为什么我的.draggable方法返回错误?

[英]Why is my .draggable method returning an error?

I am trying to make a custom scrollbar and my javascript that is supposed to make the scrollbar draggable won't work. 我正在尝试制作一个自定义滚动条,但我的使滚动条可拖动的JavaScript无法正常工作。 (I am using Chrome to test it) (我正在使用Chrome对其进行测试)

Why is this returning an error? 为什么返回错误?

// JavaScript Document
    $(document).ready(function(){
        $("#scrollbar-piece").draggable({axis: "y"});
        Uncaught TypeError: undefined is not a function
    })

Here is the html: 这是html:

<head>
    <meta charset="utf-8">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="theScriptThatHasAProblem.js"></script>
</head>
<body>
    <div class="page-container">...</div>
    <div id="scrollbar">
        <div id="scrollbar-piece"></div>
    </div>
</body>

draggable is part of the jQuery UI library that you do not have referenced. draggable是您尚未引用的jQuery UI库的一部分。

<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>

Google CDN information Google CDN信息

draggable documentation 可拖动文档

You are missing jQuery UI library. 您缺少jQuery UI库。 draggable is a component of jquery-ui this not not a part of jQuery. draggable是jquery-ui的组件,不是jQuery的一部分。
You can download stable version from https://jqueryui.com/ . 您可以从https://jqueryui.com/下载稳定版本。 Or, you can directly include that from google API as follows: 或者,您可以直接从google API中添加它,如下所示:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

You are only including the base jQuery library 您只包括基本的jQuery库

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

to use jQuery draggable & droppable include also 使用jQuery draggable & droppable包括

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script> 

Edit: Also make sure the scripts are in the correct order. 编辑:还要确保脚本的顺序正确。 jQuery has to be loaded before jQuery UI, because it depends on it. 必须依赖于jQuery UI,因此必须先加载jQuery。

Check out this fiddle: http://jsfiddle.net/8YEyc/ 看看这个小提琴: http : //jsfiddle.net/8YEyc/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM