javascript - Setting div Background using Trianglify -
i have problems using trianglify plugin. use set background of div
. how can this? couldn't find proper example.
here's sample code:
<script> var pattern = trianglify({ width: window.innerwidth, height: window.innerheight }); document.body.appendchild(pattern.canvas()) </script>
also, can have div
s different backgrounds come trianglify?
one div
here example of setting div background trianglify pattern. cheats bit , sets div child node pattern should work you.
var = document.getelementbyid('something'); var dimensions = something.getclientrects()[0]; var pattern = trianglify({ width: dimensions.width, height: dimensions.height }); something.appendchild(pattern.canvas());
the div has id of something
, css styles set on div height , width.
working example jsfiddle: http://jsfiddle.net/u55cn0fh/
multiple divs
we can expand multiple divs so:
function addtriangleto(target) { var dimensions = target.getclientrects()[0]; var pattern = trianglify({ width: dimensions.width, height: dimensions.height }); target.appendchild(pattern.canvas()); }
jsfiddle: http://jsfiddle.net/u55cn0fh/1/
multiple divs true background-image
the above appending pattern div child node instead of setting background. news can indeed use background-image
css property so:
function addtriangleto(target) { var dimensions = target.getclientrects()[0]; var pattern = trianglify({ width: dimensions.width, height: dimensions.height }); target.style['background-image'] = 'url(' + pattern.png() + ')'; }
jsfiddle: http://jsfiddle.net/abl2kc2q/
Comments
Post a Comment