Skip to content

Commit 6b36d12

Browse files
added features
1 parent 515e406 commit 6b36d12

File tree

2 files changed

+61
-15
lines changed

2 files changed

+61
-15
lines changed

README.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,60 @@ In order to use it, insert the following `<script>` tag in the `<head>` tag of y
3333
- Invoke the below function with the required arguments as shown below in your javascript file! Let's understand **these arguments** which are passed to the function!
3434

3535
```js
36-
wavy.wavy(html_element, {words: ["word-1", "word-2", "word-n"]}, {color: 'font-color'});
36+
37+
wavy(html_element, {words: ["word-1", "word-2", "word-n"]}, {color: 'font-color'});
38+
3739
```
3840

3941
- The **first argument** you should pass is an html element in which you want to place the words! It's like a wrapper element!
4042

4143
- Example for first argument:
4244

4345
```js
44-
wavy.wavy(document.querySelector(".text"), second_argument, third_argument);
46+
47+
wavy(document.querySelector(".text"), second_argument, third_argument);
48+
4549
```
4650

4751
- The **second argument** you should pass is an object with a property of `words` set to a value of an `array` containing as many words as you want to display. There is no word limit. These words will be animated in an infinite loop!
4852

4953
- Example for second argument:
5054

5155
```js
52-
wavy.wavy(document.querySelector(".text"), {words: ["Wavy", "Text", "Animation", "Library", "JavaScript"]}, third_argument);
56+
57+
wavy(document.querySelector(".text"), {words: ["Wavy", "Text", "Animation", "Library", "JavaScript"]}, third_argument);
58+
5359
```
5460

55-
- The **third argument (optional)** you should pass is an object with an option to set the color of the `text`. The color values can be `hex`, `rgb`, `hsl` or standard `css values`. Deafult color is `black`.
61+
- The **third argument** you should pass is an object with some options to set the color, fontSize, fontFamily and scale properties of the `text`. Here are all the properties that you can modify:
62+
63+
```js
64+
//these are default values
65+
66+
color: 'black', // you can also use rgb, hsl, rgba, hex
67+
fontSize: '1rem',
68+
fontFamily: 'sans-serif',
69+
transform: scale(1.5)
70+
71+
```
5672

5773
- Example for third argument:
5874

5975
```js
60-
wavy.wavy(document.querySelector(".text"), {words: ["Wavy", "Text", "Animation", "Library", "JavaScript"]}, {color: "green"});
76+
77+
wavy(
78+
document.querySelector(".text"),
79+
{
80+
words: ["Wavy", "Text", "Animation", "Library", "JavaScript"]
81+
},
82+
{
83+
color: 'green',
84+
fontSize: '2rem',
85+
fontFamily: 'Poppins, sans-serif',
86+
transform: 'scale(1.8)'
87+
}
88+
);
89+
6190
```
6291

6392
> **NOTE: The first two arguments are mandatory!**

main.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11

22
function wavy(element, words, options) {
3+
4+
const defaults = {
5+
color: 'black',
6+
fontSize: '1rem',
7+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif",
8+
transform: 'scale(1.5)'
9+
}
10+
11+
function setOptions(type){
12+
return (options !== undefined) ? ((Object.keys(options).length !== 0) ? (options[type] !== undefined ? options[type] : defaults[type]) : defaults[type]) : defaults[type];
13+
}
314

415
element.style = `
516
width: -webkit-fit-content;
617
width: -moz-fit-content;
718
width: fit-content;
8-
-webkit-transform: scale(1.5);
9-
transform: scale(1.5);
19+
-webkit-transform: ${setOptions('transform')};
20+
transform: ${setOptions('transform')};
21+
font-family: ${setOptions('fontFamily')};
22+
font-size: ${setOptions('fontSize')};
1023
`;
1124

1225
const skills_name = words.words;
13-
1426
let iteration = 1;
1527
let array_of_skills_splitted = skills_name.map((skill) => {
1628
return skill.split("");
@@ -26,7 +38,6 @@ function wavy(element, words, options) {
2638
return array_of_html_of_letter.join("");
2739
})
2840

29-
// let text_string = document.querySelector(".desc_text");
3041
let text_string = element;
3142

3243
text_string.innerHTML = array_of_final_html_string[0];
@@ -36,24 +47,22 @@ function wavy(element, words, options) {
3647
display: inline-block;
3748
opacity: 0;
3849
transform: translateY(10px);
39-
color: ${(options !== undefined) ? (options.color !== undefined ? options.color : "black") : "black"}
50+
color: ${setOptions('color')};
4051
`;
4152
})
4253

43-
let spans = element.childNodes;
44-
// let spans = document.querySelectorAll(".desc_text span");
54+
let spans = element.childNodes; // document.querySelectorAll(".class span");
4555

4656
for (let i = 0; i < spans.length; i++) {
4757
let word_length = spans.length;
4858
let zoom_in = text_string.animate([
4959
{
50-
transform: `scale(${Number(1.5)})`
60+
transform: `${setOptions('transform')}` // default = `scale(${Number(1.5)})`
5161
},
5262
{
5363
transform: `scale(${Number(1)})`
5464
}
5565
], {
56-
// delay: 300,
5766
delay: `${Number((word_length/3)*100)}`,
5867
duration: 400,
5968
iterations: 1,
@@ -104,4 +113,12 @@ function wavy(element, words, options) {
104113
text_animate();
105114
}
106115

107-
// wavy(document.querySelector(".description"), {words: ["Accenture", "Instagram", "Wordle", "Ginger"]}, {color: blue});
116+
/* --use--
117+
118+
wavy(
119+
document.querySelector(".description"),
120+
{words: ["Accenture", "Instagram", "Wordle", "Ginger"]},
121+
{color: 'green', fontSize: '2rem', fontFamily: 'Poppins, sans-serif', transform: 'scale(1.8)'}
122+
);
123+
124+
*/

0 commit comments

Comments
 (0)