var background_a; var background_b; var twidth; var theight; var xscale; var yscale; var rec; var rec2; var height = $(window).height(); var width = $(window).width(); window.onload = function () { var paper = Raphael(0,0,"100%","100%"); xscale=1; yscale=1; twidth = $(window).width(); theight = $(window).height(); background_a = paper.rect(0,0,twidth,theight) .attr({ stroke:"none", fill:"45-#f00-#808" }); rec = paper.rect("20%","20%","30%","30%") .attr({fill:"#fff",opacity:0.8,stroke:"none"}); rec2 = paper.rect("20%","60%","30%","30%") .attr({fill:"#fff",opacity:0.8,stroke:"none"}); rec3 = paper.rect("60%","20%","30%","30%") .attr({fill:"#fff",opacity:0.8,stroke:"none"}); rec4 = paper.rect("60%","60%","30%","30%") .attr({fill:"#fff",opacity:0.8,stroke:"none"}); rec5 = paper.rect("40%","40%","10%","10%") .attr({fill:"#fff",opacity:0.6,stroke:"none"}); rec6 = paper.rect("60%","40%","10%","10%") .attr({fill:"#fff",opacity:0.6,stroke:"none"}); rec7 = paper.rect("40%","60%","10%","10%") .attr({fill:"#fff",opacity:0.6,stroke:"none"}); rec8 = paper.rect("60%","60%","10%","10%") .attr({fill:"#fff",opacity:0.6,stroke:"none"}); rec9 = paper.rect("45%","55%","5%","5%") .attr({fill:"#fff",opacity:0.4,stroke:"none"}); rec10 = paper.rect("45%","55%","5%","5%") .attr({fill:"#fff",opacity:0.4,stroke:"none"}); rec11 = paper.rect("55%","45%","5%","5%") .attr({fill:"#fff",opacity:0.4,stroke:"none"}); rec12 = paper.rect("55%","55%","5%","5%") .attr({fill:"#fff",opacity:0.4,stroke:"none"}); background_b = paper.rect(0,0,twidth,theight) .attr({ stroke:"none", fill:"90-#003-#f00", opacity:.1 }); background_b.mousemove(back_mousemoved); function back_mousemoved(e){ rec.attr({x:getX(20,e.x,4) +"%", y:getY(20,e.y,4) +"%"}); rec2.attr({x:getX(20,e.x,4) +"%", y:getY(60,e.y,4) +"%"}); rec3.attr({x:getX(60,e.x,4) +"%", y:getY(20,e.y,4) +"%"}); rec4.attr({x:getX(60,e.x,4) +"%", y:getY(60,e.y,4) +"%"}); rec5.attr({x:getX(40,e.x,6) +"%", y:getY(40,e.y,6) +"%"}); rec6.attr({x:getX(40,e.x,6) +"%", y:getY(60,e.y,6) +"%"}); rec7.attr({x:getX(60,e.x,6) +"%", y:getY(40,e.y,6) +"%"}); rec8.attr({x:getX(60,e.x,6) +"%", y:getY(60,e.y,6) +"%"}); rec9.attr({x:getX(45,e.x,9) +"%", y:getY(45,e.y,9) +"%"}); rec10.attr({x:getX(45,e.x,9) +"%", y:getY(55,e.y,9) +"%"}); rec11.attr({x:getX(55,e.x,9) +"%", y:getY(45,e.y,9) +"%"}); rec12.attr({x:getX(55,e.x,9) +"%", y:getY(55,e.y,9) +"%"}); } function getX(ox,x,z){ return ox - (x/width*100)/z; } function getY(oy,y,z){ return oy - (y/height*100)/z; } }; window.onresize = function () { var w = $(window).width(); var h = $(window).height(); xscale = w/twidth; yscale = h/theight; twidth = w; theight = h; draw(); } //背景のリサイズ function draw(){ background_a.scale(xscale,yscale,0,0); background_b.scale(xscale,yscale,0,0); }
<script type="text/javascript" src="http://dl.dropbox.com/u/63305355/raphael-min.js"></script> <div id="canvas"> </div>
body,html { height:100%; margin:0; } #canvas { height:99%; background:#000; text-align:center; } .text{ letter-spacing: 20px; color:#fff; font-size:150%; width:60%; height:60%; position:absolute; left:20%; top:40%; z-index:1; }