如何在jQuery中使用Sortable对div进行水平排序 [英] How to horizontally sort divs using Sortable in JQuery

查看:215
本文介绍了如何在jQuery中使用Sortable对div进行水平排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找将div在容器div中水平排序的方法.
我在JQuery网站上找到了示例,但这是垂直排序.我要水平.

I am looking to sort my divs horizontally in a container div.
I found an example on JQuery website but that is vertical sorting. I want it horizontal.

我要在#sortable <div>中进行排序.

请您指导我如何以水平方式转换此垂直排序.

Will you please guide me how can I convert this vertical sorting in horizontal manner.

<style type="text/css">
    #draggable1 { width: 150px; height: 35px; padding: 0.5em; }
    #draggable2 { width: 150px; height: 35px; padding: 0.5em; }
    #draggable3 { width: 150px; height: 35px; padding: 0.5em; }

    #sortable { width: 700px; height: 35px; padding: 0.5em; }
</style>

JavaScript

<script type="text/javascript">
    $(function() {  
        $("#sortable").sortable({
            revert: true
        }); 
    });
</script>

HTML

<div class="demo">
    <div id="sortable" class="ui-state-default">
        <div id = "draggable1" class="ui-state-default">Home</div>
        <div id = "draggable2" class="ui-state-default">Contact Us</div>
        <div id = "draggable3" class="ui-state-default">FAQs</div>
    </div>
</div>

推荐答案

您可以添加以下CSS样式:

You can just add this CSS style:

#sortable>div { float: left; }

它们将是水平的并且仍然可以排序. 您可以在此处查看其运行演示.

And they'll be horizontal and still sortable. You can see a demo of it in action here.

这篇关于如何在jQuery中使用Sortable对div进行水平排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆