Skip to content

Instantly share code, notes, and snippets.

@teaplanet
Created December 23, 2014 15:56
Show Gist options
  • Select an option

  • Save teaplanet/57e249dc2c77840829d0 to your computer and use it in GitHub Desktop.

Select an option

Save teaplanet/57e249dc2c77840829d0 to your computer and use it in GitHub Desktop.
Ractive.js Tutorial 3-3
<!-- http://learn.ractivejs.org/expressions/3 -->
<script src='http://cdn.ractivejs.org/latest/ractive.min.js'></script>
<div id='container'></div>
<script id='template' type='text/ractive'>
<p>red:</p>
<div style='background-color: red; width: {{red * 100}}%;'></div>
<p>green:</p>
<div style='background-color: green; width: {{green * 100}}%;'></div>
<p>blue:</p>
<div style='background-color: blue; width: {{blue * 100}}%;'></div>
<p><strong>result:</strong></p>
<div style='background-color: rgb({{Math.round(red * 255)}}, {{Math.round(green * 255)}}, {{Math.round(blue * 255)}})'>
</div>
</script>
var ractive = new Ractive({
el: 'container',
template: '#template',
data: {
red: 0.45,
green: 0.61,
blue: 0.2
}
});
// ractive.set('red', 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment