javascript - multiple canvas as buttons with onclick event -
i'm having big problems canvas code i'm using 1 time in page (in logo) working fine, , i'm trying use buttons menu , here problem, don't know what's im doing wrong, hope of u me.
it's code i'm using logo , working fine:
html code:
<html> <head> <title>canvas</title> </head> <body> <div id="container"> <div id="logo"> <canvas style="" width="800" id="broken-glass"></canvas> <h1 style="color: rgba(250, 250, 250, 0.95);" id="logo-title">canvas</h1> </div> <script type="text/javascript"> (function() { var iscanvassupported = function () { var elem = document.createelement('canvas'); return !!(elem.getcontext && elem.getcontext('2d')); }; if( iscanvassupported() ) { var canvas = document.getelementbyid('broken-glass'), context = canvas.getcontext('2d'), width = canvas.width = math.min(800, window.innerwidth), height = canvas.height, numtriangles = 100, rand = function(min, max){ return math.floor( (math.random() * (max - min + 1) ) + min); }; window.drawtriangles = function(){ context.clearrect(0, 0, width, height); var hue = rand(0,360); var increment = 80 / numtriangles; for(var = 0; < numtriangles; i++) { context.beginpath(); context.moveto(rand(0,width), rand(0,height) ); context.lineto(rand(0,width), rand(0,height) ); context.lineto(rand(0,width), rand(0,height) ); context.globalalpha = 0.5; context.fillstyle = 'hsl('+math.round(hue)+', '+rand(15,60)+'%, '+ rand(10, 60) +'%)'; context.closepath(); context.fill(); hue+=increment; if(hue > 360) hue = 0; } canvas.style.csstext = '-webkit-filter: contrast(115%);'; }; document.getelementbyid('logo-title').style.color = 'rgba(250, 250, 250, 0.95)'; drawtriangles(); var el = document.getelementbyid('logo'); el.onclick = function() { drawtriangles(); }; } })(); </script> </div> </body> </html>
and it's css code:
#broken-glass { position: absolute; left: 0px; top: 0px; width: 100%; } #logo h1 { text-align: center; font-weight: 700; width: 100%; color: #000; position: absolute; left: 0px; -moz-user-select: none; cursor: pointer; margin-top: 27px; font-size: 63px; line-height: 1.4; top: 0px; margin-bottom: 5px; text-rendering: optimizelegibility; font-family: calibri,"pt sans","trebuchet ms","helvetica neue",arial; }
the big problem comes when change id's (#) classes (.) , "id" tag "class" tag in html, canvas overlapped... text of h1 tag out of canvas... , hell of problems, can tell me i'm doing wrong?, how fix it, i'm trying during hours...
too in advance!.
you may try putting !important in every code in css. example:
text-align: center !important; font-weight: 700 !important;
this fixed problem before, fix yours also.
Comments
Post a Comment