2017-08-12 3 views
0

私は次のスクリプトを使用しています.draggable、 ユーザーがクリックしてテキストをドラッグするときに、親スクロール内でテキストスクロールを水平にドラッグする必要があります。jquery draggableどのようにxの拘束を維持し、ドラッグを動作させる?

現在このコードを使用していますが、正しく動作しません。 どうしたのですか?それを修正するには?

例:http://jsfiddle.net/t1smb6u8/

jQuery("#child").draggable({ 
 
    cursor: "move", 
 
    axis: "x", 
 
    containment: "parent" 
 
});
.parent { 
 
    width: 300px; 
 
    border: 5px solid red; 
 
    overflow: scroll; 
 
} 
 

 
#child { 
 
    width: 1000px; 
 
    padding: 10px; 
 
}
<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
 
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script> 
 
<div class="parent"> 
 

 
    <div id="child"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It 
 
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop 
 
    publishing software like Aldus PageMaker including versions of Lorem Ipsum </div> 
 

 

 
</div>

答えて

0

ちょうどそれが動作しませんcontainment: "parent"

jQuery("#child").draggable({ 
 
    cursor: "move", 
 
    axis: "x", 
 
    //containment: "parent" 
 
});
.parent { 
 
    width: 300px; 
 
    border: 5px solid red; 
 
    overflow: scroll; 
 
} 
 

 
#child { 
 
    width: 1000px; 
 
    padding: 10px; 
 
}
<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
 
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script> 
 
<div class="parent"> 
 

 
    <div id="child"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It 
 
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop 
 
    publishing software like Aldus PageMaker including versions of Lorem Ipsum </div> 
 

 

 
</div>

+0

削除オブジェクトはそのサイズ内でのみスクロールする必要があります。ユーザーがテキストをスクロールすると、赤いボックスで白しか表示されないほどスクロールできます。スクロールの制限を適用する必要があります。何か案は?ありがとう – Radex

+0

@Radexは、ドラッグを '開始'の制約を追加し、それが左または右の場合はfalseを返します –

+0

ライブの例を追加してください、あなたの答えを受け入れることができますか?ありがとう! – Radex

関連する問題