最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery sortable only by dragging header - Stack Overflow

programmeradmin1浏览0评论

I want to have two sections on my webpage which can be dragged left or right of each other:

<style>
#sortableitem {
    width: 100px;
    height: 70px;
    float:left;
    list-style-type: none;
}
.content {
    background:lightgrey;
}
.header {
    background:grey;
}
<style>

<ul id='sortable'>
<li id='sortableitem'>
    <div class='header'>ITEM 1</div>
    <div class='content'>Content here</div>
</li>
<li id='sortableitem'>
    <div class='header'>ITEM 2</div>
    <div class='content'>Content here</div>
</li>
</ul>

<script>
$(document).ready(function () {
    $("#sortable").sortable();
});
</script>

This is working here: /

However, I only want to be able to drag using the header section. I have content which I want to be selectable.

How do I get this to work so that I can drag via the header, but still have normal control over mouse events in the content area ?

I want to have two sections on my webpage which can be dragged left or right of each other:

<style>
#sortableitem {
    width: 100px;
    height: 70px;
    float:left;
    list-style-type: none;
}
.content {
    background:lightgrey;
}
.header {
    background:grey;
}
<style>

<ul id='sortable'>
<li id='sortableitem'>
    <div class='header'>ITEM 1</div>
    <div class='content'>Content here</div>
</li>
<li id='sortableitem'>
    <div class='header'>ITEM 2</div>
    <div class='content'>Content here</div>
</li>
</ul>

<script>
$(document).ready(function () {
    $("#sortable").sortable();
});
</script>

This is working here: http://jsfiddle.net/gTUSw/

However, I only want to be able to drag using the header section. I have content which I want to be selectable.

How do I get this to work so that I can drag via the header, but still have normal control over mouse events in the content area ?

Share Improve this question edited Mar 11, 2013 at 14:08 SteveP asked Mar 11, 2013 at 13:56 StevePSteveP 19.1k9 gold badges48 silver badges62 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 23

You want to use the handle option, like:

$("#sortable").sortable({ handle: ".header" });

You can see a working example here: http://jsfiddle.net/gTUSw/1/ - you can also see a wealth of options on the full api documentation here.

发布评论

评论列表(0)

  1. 暂无评论