Data attributes
See original GitHub issueHey,
I have one problem. I can’t add gradients via data attribute.
V1 - this works ok:
var my_gradient = [['#000000', '#111111'],['#444444', '#777777'],['#aaaaaa', '#ffffff']];
var granimInstance = new Granim({
states : {
"default-state": {
gradients: my_gradient
}
}
});
V2 - Don’t work
var my_gradient = el.getAttribute('data-gradients') || [['#000000', '#111111'],['#444444', '#777777'],['#aaaaaa', '#ffffff']];
var granimInstance = new Granim({
states : {
"default-state": {
gradients: my_gradient
}
}
});
<div data-gradients="[['#000000', '#111111'],['#444444', '#777777'],['#aaaaaa', '#ffffff']]">
<canvas></canvas>
</div>
Please help.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Using data attributes - Learn web development | MDN
data -* attributes allow us to store extra information on standard, semantic HTML elements without other hacks such as non-standard attributes, ...
Read more >HTML data-* Attribute - W3Schools
The data-* attribute is used to store custom data private to the page or application. The data-* attribute gives us the ability to...
Read more >A Complete Guide to Data Attributes | CSS-Tricks
Data attributes are often referred to as data-* attributes, as they are always formatted like that. The word data , then a dash...
Read more >What is a data attribute? Definition, Types & Examples
In short, a data attribute is a single-value descriptor for a data point or data object. It exists most often as a column...
Read more >HTML | data-* Attributes - GeeksforGeeks
Custom Data Attributes allow you to add your own information to tags in HTML. Even though the name suggests otherwise, these are not ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I guess it’s because “my_gradient” is a string in the second case. You’ll need to decode that with
my_gradient = JSON.parse(my_gradient);
Yes, I know. I must add gradients via the data attributes and I can’t use doublequotes - this solution is easier to edit for users and I can use it multiple times.