1+ ![ Animation] ( ./demo.png )
2+
13# DepthText
24
35DepthText is a lightweight, dependency-free JavaScript library that creates smooth multi-layer 3D text with depth, parallax, and interactive rotation.
@@ -18,6 +20,7 @@ It is the spiritual successor of ztext.js, but rewritten from scratch with a cle
1820- 🔥 ** No dependencies** , only 4–6 KB minified
1921- 📦 Works with bundlers, ES modules, and browsers
2022- 🖼️ ** Supports images, SVGs, and emojis** within text content
23+ - 🎭 ** Custom CSS classes** for advanced styling control
2124
2225---
2326
@@ -75,6 +78,7 @@ DepthText can be configured using either:
7578| ` data-depth-fade ` | boolean | ` false ` | Fade layers as depth increases |
7679| ` data-depth-eventdirection ` | number | ` 1 ` | Invert pointer/scroll direction |
7780| ` data-depth-eventrotation ` | number | ` 20 ` | Max rotation angle on interaction |
81+ | ` data-depth-add-class ` | string | ` "" ` | Custom CSS class(es) to add to each layer |
7882
7983---
8084
@@ -89,11 +93,93 @@ const instance = new DepthTextInstance(element, {
8993 fade: false ,
9094 event : " pointer" ,
9195 eventRotation: 20 ,
96+ addClass: " my-custom-class" , // New option for custom styling
9297});
9398```
9499
95100---
96101
102+ ## 🎨 Custom Styling with ` addClass `
103+
104+ The new ` addClass ` option allows you to apply custom CSS classes to all depth layers for advanced styling control.
105+
106+ ### Basic Usage
107+
108+ ``` html
109+ <h1 class =" depthtext" data-depth =" 10" data-depth-event =" pointer" data-depth-add-class =" gradient-text" >Stylized Text</h1 >
110+ ```
111+
112+ ``` css
113+ .gradient-text {
114+ background : linear-gradient (45deg , #ff6b6b , #4ecdc4 );
115+ -webkit-background-clip : text ;
116+ -webkit-text-fill-color : transparent ;
117+ background-clip : text ;
118+ }
119+ ```
120+
121+ ### Multiple Classes
122+
123+ You can add multiple classes separated by spaces:
124+
125+ ``` js
126+ new DepthTextInstance (element, {
127+ addClass: " gradient-text shadow-effect animated" ,
128+ });
129+ ```
130+
131+ Or via HTML:
132+
133+ ``` html
134+ <div data-depth =" 5" data-depth-add-class =" class1 class2 class3" >Multi-styled text</div >
135+ ```
136+
137+ ### Advanced Styling Examples
138+
139+ ``` css
140+ /* Neon glow effect */
141+ .neon-glow {
142+ color : #00ffff ;
143+ text-shadow : 0 0 10px #00ffff , 0 0 20px #00ffff ;
144+ }
145+
146+ /* Metallic gradient */
147+ .metallic {
148+ background : linear-gradient (90deg , #c0c0c0 , #e8e8e8 , #c0c0c0 );
149+ -webkit-background-clip : text ;
150+ -webkit-text-fill-color : transparent ;
151+ }
152+
153+ /* Rainbow animation */
154+ @keyframes rainbow {
155+ 0% ,
156+ 100% {
157+ color : #ff0000 ;
158+ }
159+ 16% {
160+ color : #ff7f00 ;
161+ }
162+ 33% {
163+ color : #ffff00 ;
164+ }
165+ 50% {
166+ color : #00ff00 ;
167+ }
168+ 66% {
169+ color : #0000ff ;
170+ }
171+ 83% {
172+ color : #8b00ff ;
173+ }
174+ }
175+
176+ .rainbow-text {
177+ animation : rainbow 3s linear infinite ;
178+ }
179+ ```
180+
181+ ---
182+
97183## 🌐 Automatic Initialization
98184
99185If you want DepthText to automatically enhance all matching elements:
@@ -137,6 +223,15 @@ You can style them globally:
137223}
138224```
139225
226+ With the ` addClass ` option, you can target specific instances:
227+
228+ ``` css
229+ .depthtext-layer.my-style {
230+ color : #ff6b6b ;
231+ font-weight : bold ;
232+ }
233+ ```
234+
140235---
141236
142237## 📦 Browser Usage (no bundler)
@@ -171,6 +266,7 @@ export default function DepthComponent() {
171266 layers: 10 ,
172267 depth: " 1rem" ,
173268 event : " pointer" ,
269+ addClass: " gradient-effect" , // Custom styling
174270 });
175271
176272 // Cleanup on unmount
@@ -196,6 +292,7 @@ export default function DepthComponent() {
196292 dt = new DepthTextInstance (textRef .value , {
197293 layers: 10 ,
198294 event : " pointer" ,
295+ addClass: " custom-style" ,
199296 });
200297 }
201298 });
@@ -228,6 +325,7 @@ export class DepthTextComponent implements AfterViewInit, OnDestroy {
228325 this .dt = new DepthTextInstance (this .textRef .nativeElement , {
229326 layers: 10 ,
230327 event: " pointer" ,
328+ addClass: " angular-depth-style" ,
231329 });
232330 }
233331
@@ -252,7 +350,7 @@ DepthText works with various content types:
252350### Example with mixed content:
253351
254352``` html
255- <h1 class =" depthtext" data-depth =" 5" data-depth-event =" pointer" >
353+ <h1 class =" depthtext" data-depth =" 5" data-depth-event =" pointer" data-depth-add-class = " colorful " >
256354 Hello World! 🚀
257355 <svg width =" 30" height =" 30" ><circle cx =" 15" cy =" 15" r =" 10" fill =" blue" /></svg >
258356 <img src =" logo.png" width =" 40" alt =" Logo" />
@@ -265,7 +363,7 @@ Images should be loaded before initialization for best results.
265363Very large images may impact performance.
266364External SVGs (<img src =" icon.svg " >) work like regular images.
267365
268- ## 🐛 Known Issues & Notes
366+ ## 🛠 Known Issues & Notes
269367
270368- DepthText uses CSS transforms; parent elements must not flatten 3D contexts.
271369- Avoid nested DepthText unless you understand ` transform-style: preserve-3d ` .
@@ -283,7 +381,7 @@ If you add a major feature, please include documentation updates.
283381
284382## 📄 License
285383
286- MIT License — free to use in commercial and open-source projects.
384+ MIT License – free to use in commercial and open-source projects.
287385
288386---
289387
0 commit comments