question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hey,

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:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
SebaGnichcommented, Sep 11, 2017

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);

0reactions
MichaelRisecommented, Sep 14, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found