Can I use jQuery to easily shift li elements up or down?

前端 未结 3 1865
小鲜肉
小鲜肉 2020-12-15 11:05

I have a menu like this:

    
  • Home
3条回答
  •  甜味超标
    2020-12-15 11:46

    You can also use display: flex on the parent then you can use order

    function reset()
    {
      jQuery("#a").css("order", 10);
      jQuery("#b").css("order", 20);
      jQuery("#c").css("order", 30);
    }
    
    function reorder1()
    {
      jQuery("#a").css("order", 30);
      jQuery("#b").css("order", 20);
      jQuery("#c").css("order", 10);
    }
    
    function reorder2()
    {
      jQuery("#a").css("order", 30);
      jQuery("#b").css("order", 10);
      jQuery("#c").css("order", 20);
    }
    #main { display: flex; }
    #a { color: red; }
    #b { color: blue; }
    #c { color: green; }
    
    
    Foo
    Bar
    Baz

提交回复
热议问题