FloatingCircle
Dynamically add text as a circle with visual cues of collision simulation, completely in-browser
Install / Use
/learn @bofeiw/FloatingCircleREADME
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

How to use
- Include
adjustSize.cssin your HTML.
<link rel="stylesheet" href="css/adjustSize.css">
- Include
adjustSize.jsandanime.min.jsin your HTML.
<script src="js/adjustSize.js"></script>
<script src="js/anime.min.js"></script>
- 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:
- Circle collision detection with mouseover effect using D3.js
- Circle collision with resizeable circle and collapsible content using D3.js
License
"Anti 996" License, do whatever you want if you or your company does not exploit employees
Related Skills
node-connect
349.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
