Skip to content

对绝对定位的 div 进行排序,为 flex 布局作准备

Notifications You must be signed in to change notification settings

lewis617/absolute-sort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

absolute-sort

对绝对定位的 div 进行排序,为 flex 布局作准备。

使用方法

引入 absoluteSort.js 的 absoluteSort 方法

// 注意,Math.floor(Math.random() * 40) 会随机生成 0-39,这是为了让 div 可以随机布局,来测试一些误差
const divList1 = [
        {
            x: 50 + Math.floor(Math.random() * 40),
            y: 50 + 200 + Math.floor(Math.random() * 40),
            val: 1,
        },
        {
            x: 50 + 200 + Math.floor(Math.random() * 40),
            y: 50 + Math.floor(Math.random() * 40),
            val: 2,
        },
        {
            x: 50 + Math.floor(Math.random() * 40),
            y: 50 + Math.floor(Math.random() * 40),
            val: 3,
        },


        {
            x: 50 + 200 + Math.floor(Math.random() * 40),
            y: 50 + 200 + Math.floor(Math.random() * 40),
            val: 4,
        },
    ];

const divList2 = absoluteSort(divList1);

console.log(divList2);
// 变成 3->2->1->4,即左右上下的顺序
// [{"x":89,"y":65,"val":3},{"x":286,"y":85,"val":2},{"x":52,"y":263,"val":1},{"x":264,"y":265,"val":4}]

About

对绝对定位的 div 进行排序,为 flex 布局作准备

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published