Code Monkey home page Code Monkey logo

hashposition's Introduction

随机散列排布

web 端实现在盒子类将指定的子节点随机排列,并不重叠

使用方法

hashPosition 函数
参数 1:dom 对象
参数 2:数字时表明排列子元素宽高一样 只针对圆时一样,正方形时宽高都应该是正方形宽的根号 2 倍,参数为对象时
width: 指定子元素宽高固定
minWidth,maxWidth在子元素宽高在范围内时使用 space:指定子元素最小间隔,默认在为最大宽度的0.2倍

宽高一样的圆排列时

avatar demo:

hashPosition(document.getElementById("hash-box"), 40)

子元素宽高在一定范围类

avatar demo:

hashPosition(document.getElementById("hash-box1"), {
  minWidth: 20,
  maxWidth: 50,
})

方形元素排列

avatar demo:

hashPosition(document.getElementById("hash-box2"), {
  width: 30,
  // 设置方向元素间的间隔 在45对角排列是元素中心点距离是30倍根号2,但width设置30时最小间距是30*0.2,这时需要手动调整间距
  space: 30 * (Math.pow(2, 0.5) - 1),
})

长方形元素排列

avatar demo:

hashPosition(document.getElementById("hash-box2"), {
  width: 30,
  // 与正方形**一直,只是width是长方形的最大边
  space: 30 * (Math.pow(2, 0.5) - 1),
})

hashposition's People

Contributors

kiss-keray avatar

Stargazers

lzl avatar logeast avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.