473,379 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Canvas repeat and align problem, help pls.

ilya Kraft
134 100+
Hello I have this interactive canvas as a background of my web, it is on 100% width and high, but when I add content that continues longer than canvas and you have to scroll down, canvas is not repeating down y axis.

Also can anyone tell how can i center align absolute positioned <div>.

I added white box that is longer than canvas, if you scroll down you start to see black background, how can I make canvas repeat down y-axis and how do i center that white box (which is absolute positioned div)

Here is code:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html> 
  2. <html lang="en"> 
  3. <head> 
  4. <meta charset=utf-8 /> 
  5. <title>Canvas by Ilya</title> 
  6. <style> 
  7. body {
  8.     background: #000;
  9.     margin-left: 0px;
  10.     margin-top: 0px;
  11.     margin-right: 0px;
  12. }
  13. canvas {
  14.   position: absolute;
  15.   top: 0;
  16.   left: 0;
  17.   height: 100%;
  18.   width: 100%;
  19.  
  20. }
  21. body,td,th {
  22.     color: #000;
  23. }
  24.  
  25.  
  26. #repeattest {
  27.     background-color: #FFF;
  28.     position: absolute;
  29.     height: 2552px;
  30.     width: 88px;
  31.     left: 62px;
  32.     top: 1px;
  33. }
  34. </style> 
  35.  
  36. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  37. </head> 
  38. <body> 
  39. <canvas height="600" width="600"></canvas> 
  40. <script> 
  41. var canvas = document.getElementsByTagName('canvas')[0],
  42.     ctx = null,
  43.     grad = null,
  44.     body = document.getElementsByTagName('body')[0],
  45.     color = 255;
  46.  
  47. if (canvas.getContext('2d')) {
  48.   ctx = canvas.getContext('2d');
  49.   ctx.clearRect(0, 0, 600, 600);
  50.   ctx.save();
  51.   // Create radial gradient
  52.   grad = ctx.createRadialGradient(0,0,0,0,0,600); 
  53.   grad.addColorStop(0, '#000');
  54.   grad.addColorStop(1, 'rgb(' + color + ', ' + color + ', ' + color + ')');
  55.  
  56.   // assign gradients to fill
  57.   ctx.fillStyle = grad;
  58.  
  59.   // draw 600x600 fill
  60.   ctx.fillRect(0,0,600,600);
  61.   ctx.save();
  62.  
  63.   body.onmousemove = function (event) {
  64.     var width = window.innerWidth, 
  65.         height = window.innerHeight, 
  66.         x = event.clientX, 
  67.         y = event.clientY,
  68.         rx = 600 * x / width,
  69.         ry = 600 * y / width;
  70.  
  71.     var xc = ~~(256 * x / width);
  72.     var yc = ~~(256 * y / height);
  73.  
  74.     grad = ctx.createRadialGradient(rx, ry, 0, rx, ry, 0.01); 
  75.     grad.addColorStop(0, '#000');
  76.     grad.addColorStop(1, ['rgb(', xc, ', ', (255 - xc), ', ', yc, ')'].join(''));
  77.     // ctx.restore();
  78.     ctx.fillStyle = grad;
  79.     ctx.fillRect(0,0,600,600);
  80.     // ctx.save();
  81.   };
  82. }
  83. </script>
  84. <div id="repeattest">
  85.   <p>Scroll</p>
  86.   <p> Down<br>
  87.   </p>
  88. </div>
  89.  
  90.  
  91. </body> 
  92. </html>
  93.  
Jan 12 '11 #1

✓ answered by Rabbit

Change the canvas from absolute to fixed. I'm not sure what you mean by center the div. Are you talking about centering what's inside the div? Or centering the div on the page?

5 2869
Rabbit
12,516 Expert Mod 8TB
Change the canvas from absolute to fixed. I'm not sure what you mean by center the div. Are you talking about centering what's inside the div? Or centering the div on the page?
Jan 12 '11 #2
ilya Kraft
134 100+
changing it to fixed position helped thanks, i mean centering a div on a page.
Thanks for help with canvas again )))
Jan 12 '11 #3
Rabbit
12,516 Expert Mod 8TB
Have one master div that's absolutely positioned at 0,0 with 100% width and height. That will be the wrapper for the rest of the content. You can now treat everything within that div as if it's the <body> of the document. You would center anything within it the same way you would center it if you didn't have a canvas for a background or a div as a wrapper.
Jan 12 '11 #4
ilya Kraft
134 100+
Thank you again ))) you are awesome!!! ;D
Jan 12 '11 #5
Rabbit
12,516 Expert Mod 8TB
No problem, good luck.
Jan 12 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Chen Yang | last post by:
suppose there're three String a, b and c, the length are not fixed. how can i make the format a b c so that three arrays align to the left? ok, i know it's stupid.. but i don't think using...
3
by: Marcel | last post by:
I'm running MySQL version 4.1.7-nt. When I submit the following query: SELECT DISTINCT pet from pets; I get: dog cat lama
2
by: Felipe Gasper | last post by:
I'm trying to make some "sub-cells" in an HTML table and to control their positioning and content presentation via CSS. In the table at the following URL: ...
3
by: Sanjay | last post by:
Hi, I am calling COM + dll from VB.net class. When two clients invoke same method of com+ dll concurrently both client requests fail. COM + dll is insatlled in Library package. I got...
3
by: Rob | last post by:
I have a form - when you click the submit button, it appends a variable to the URL (e.g. xyz.cgi?inputID=some_dynamic_variable) It also opens a new page. Now, that some_dynamic_variable is...
11
by: Ceri Williams | last post by:
I followed the excellent MSDN article "Code Generation in the .NET Framework Using XML Schema" to build a substitute for the limited xsd.exe. My code works fine under .NET framework 1.1, but after...
0
by: a.theil | last post by:
Hello! First, I´m greenhorn to vb.net. I do - proIDKernel = Shell(txtKommandozeile, vbMinimizedFocus) AppActivate(proIDKernel) SendKeys.SendWait(strK) SendKeys.SendWait("{ENTER}")
4
by: Tom | last post by:
Hi: I'm having a problem with a simple report in a simple database. Basically it's an issue tracking database - what is the issue, what is the proposed solution, who is responsible, a tracking...
2
by: mrbadboy | last post by:
Hi, I tried to set aling DIV to center using text-align:cener. It works in IE but not in Mozilla. Whats the alternate solution for Mozilla ?. Thanks.
5
by: bogfart | last post by:
Hi all, In brief, this is what's happening (very annoying): - I made 5 HTML/CSS pages coding them by hand; - First I made one page and I used that page for making other pages, just with small...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.