猫头鹰旋转木马与jQuery UI Draggable

时间:2014-05-10 13:54:07

标签: javascript jquery jquery-ui draggable carousel

我试图让我的猫头鹰旋转木马中的元素可以拖动,但它似乎并没有起作用。这是我的设置:

HTML:

<div id="owl" class="owl-carousel">
        <div class="my-owl-item"></div>
        <div class="my-owl-item"></div>
        <div class="my-owl-item"></div>
</div>

JS / jQuery:

jQuery(function(){
        //init carousel
        $(".owl-carousel").owlCarousel({
            autoPlay:false,
            rewindSpeed:500,
            navigation:false,
            pagination:false,
            slideSpeed:1500,
            mouseDrag:false
        });

        //set up draggable
        jQuery( '.my-owl-item' ).draggable({
            start: function( event, ui ) {console.log('dragging');},
            helper : 'clone'
        });
});

我已禁用鼠标拖动旋转木马,因为我可能是原因。正在触发可拖动的启动功能 - 它按预期将调试消息输出到控制台。该元素也被克隆。所以一切似乎都有效,除非我无法拖动它!

任何帮助非常感谢。

1 个答案:

答案 0 :(得分:3)

为此,您需要编辑owl-carousel.js文件以便与可拖动事件完美配合,因为在owl-carousel.js默认情况下它只能在x方向上拖动。因为我编辑了js文件,所以你可以实现你正在寻找的功能。 这是Edited js文件的链接 https://www.dropbox.com/s/2lia6kkeimka94o/owl.carousel.js

在你jquery初始化Owl-carasoul的地方,只需删除mouseDrag事件,并将jquery ui放在body标签的末尾。 ħ

这是我的配置

<script>
    $(document).ready(function() {

      var owl = $("#owl-demo");

      owl.owlCarousel({

        // Define custom and unlimited items depending from the width
        // If this option is set, itemsDeskop, itemsDesktopSmall, itemsTablet, itemsMobile etc. are disabled
        // For better preview, order the arrays by screen size, but it's not mandatory
        // Don't forget to include the lowest available screen size, otherwise it will take the default one for screens lower than lowest available.
        // In the example there is dimension with 0 with which cover screens between 0 and 450px

        itemsCustom : [
          [0, 2],
          [450, 4],
          [600, 7],
          [700, 9],
          [1000, 10],
          [1200, 12],
          [1400, 13],
          [1600, 15]
        ],
        navigation : true

      });



    });
    </script>

<script>
jQuery( '.item' ).draggable({
start: function( event, ui ) {console.log('dragging');}
});
</script>

和头标记

<!-- Owl Carousel Assets -->
    <link href="../owl-carousel/owl.carousel.css" rel="stylesheet">
    <link href="../owl-carousel/owl.theme.css" rel="stylesheet">

并且html标记是

<div id="demo">
        <div id="owl-demo" class="owl-carousel">

          <div class="item"><h1>1</h1></div>
          <div class="item"><h1>2</h1></div>
          <div class="item"><h1>3</h1></div>
          <div class="item"><h1>4</h1></div>
          <div class="item"><h1>5</h1></div>
          <div class="item"><h1>6</h1></div>
          <div class="item"><h1>7</h1></div>
          <div class="item"><h1>8</h1></div>
          <div class="item"><h1>9</h1></div>
          <div class="item"><h1>10</h1></div>
          <div class="item"><h1>11</h1></div>
          <div class="item"><h1>12</h1></div>
          <div class="item"><h1>13</h1></div>
          <div class="item"><h1>14</h1></div>
          <div class="item"><h1>15</h1></div>
          <div class="item"><h1>16</h1></div>
          <div class="item"><h1>17</h1></div>
          <div class="item"><h1>18</h1></div>
          <div class="item"><h1>19</h1></div>
          <div class="item"><h1>20</h1></div>

        </div>
    </div>