admin管理员组

文章数量:1417029

I am trying to make a custom scrollbar and my javascript that is supposed to make the scrollbar draggable won't work. (I am using Chrome to test it)

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:

<head>
    <meta charset="utf-8">
    <script src=".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>

I am trying to make a custom scrollbar and my javascript that is supposed to make the scrollbar draggable won't work. (I am using Chrome to test it)

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:

<head>
    <meta charset="utf-8">
    <script src="http://ajax.googleapis./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>

Share Improve this question asked Apr 10, 2014 at 19:58 An Original AliasAn Original Alias 2033 silver badges16 bronze badges 1
  • 1 Are you missing a script include? jqueryUI perhaps? – n8wrl Commented Apr 10, 2014 at 20:00
Add a ment  | 

3 Answers 3

Reset to default 2

draggable is part of the jQuery UI library that you do not have referenced.

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

Google CDN information

draggable documentation

You are only including the base jQuery library

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

to use jQuery draggable & droppable include also

<script type="text/javascript" src="http://ajax.googleapis./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.

Check out this fiddle: http://jsfiddle/8YEyc/

You are missing jQuery UI library.draggable is a ponent of jquery-ui this not not a part of jQuery.
You can download stable version from https://jqueryui./. Or, you can directly include that from google API as follows:

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

本文标签: javascriptWhy is my draggable method returning an errorStack Overflow