Coder Social home page Coder Social logo

bofeiw / floatingcircle Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 3.0 7.19 MB

Dynamically add text as a circle with visual cues of collision simulation, completely in-browser

Home Page: https://bofeiw.github.io/floatingCircle

License: Other

CSS 8.77% JavaScript 91.23%
collision-detection collision collision-handling apple-music circle html5 html js javascript

floatingcircle's Introduction

Floating Circle

A light weight circle-circle collision simulation with visual cues.
It can dynamically add data at anytime.
Inspired by Apple Music's introduction scene on iOS.

Demo

Try here: https://bofeiw.github.io/floatingCircle

demo.gif

How to use

  1. Include adjustSize.css in your HTML.
<link rel="stylesheet" href="css/adjustSize.css">
  1. Include adjustSize.js and anime.min.js in your HTML.
<script src="js/adjustSize.js"></script>
<script src="js/anime.min.js"></script>
  1. Create a container and assign an ID:
<div id="yourID"></div>

Note: the div will occupy 100% of width and height of its parent, please give it some space! This is essential! 4. Use add to dynamically add data!

<script>
    circleManager = new CircleManager('yourID');
    circleManager.add("Hello there!");
    circleManager.add("I'm glad to see you!");
    circleManager.add("How are you?", 1000);
    circleManager.add("This is really a fun demo", 2000);
    circleManager.add("Hope you'll enjoy it!", 5000);
    circleManager.add("Have fun!", 10000);
    circleManager.add("Why are you still there !!!!!!!!!", 20000);
</script>

add Receive two parameters, the first one is the content of the circle, and the second one is optional, is the delay of the circle to be added, default to 0.

You can also see this example.

Callback onclick

After creating a CircleManager, you can pass your onclick callback to manager. By default, when a circle is clicked, the content of the circle is logged. You can change the default behaviour by adding this:

circleManager.onclick = (content) => {
    // this is default onclick but you can always change it
    // do whatever you want with content!
    console.log(content);
}

Your callback should receive one parameter, content, which is the string inside the clicked circle.

Browser support

  • Apple Safari: supported
  • Google Chrome: supported
  • Microsoft Edge: supported
  • Microsoft IE: not supported. If you want use it in IE, you need to use Bable to translate all js files into compatible versions (i.e. string literals are not supported in IE).
  • Other Browsers: to be tested

TODO

  • speed up algorithm (a bit slow when adding lots of circles (around 50))
  • add more info to callback (eg. pass some id back)
  • hovering on a circle that is surrounded by lots of circles caus-es enlarging animation to be not smooth (around 50)
  • add drag effect
  • add more callbacks (onempty etc.)
  • add radius as a percentage to measure the percentage of each two circles to displace in static collision
  • two circles might not fit inside container

Contribution

You are welcome to contribute! You can consider to kill some TODOs.

Related projects

Here are some of the projects I tried and are related to this project:

License

"Anti 996" License, do whatever you want if you or your company does not exploit employees

floatingcircle's People

Contributors

bofeiw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.