473,809 Members | 2,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Canvas repeat and align problem, help pls.

ilya Kraft
134 New Member
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
5 2882
Rabbit
12,516 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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 New Member
Thank you again ))) you are awesome!!! ;D
Jan 12 '11 #5
Rabbit
12,516 Recognized Expert Moderator MVP
No problem, good luck.
Jan 12 '11 #6

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

Similar topics

2
2204
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 StringTokenizer to implement my own format is a good idea... plez help me out, thanks a lot!
3
1578
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
6181
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: https://fshn3152.foods.uiuc.edu/~fgasper/erf.html what I'm immediately trying to do is vertically position the text and checkboxes in all four "Statement Date" sub-cells (created with <span> elements).
3
1703
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 same problem when when I changed packaege from Library to
3
2447
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 actually the name of a form element on the parent window. On the new page, I have this javascript: ---- var var2 = location.search.substring(9); document.write(var2)
11
3385
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 installing .net framework service pack 1, my code breaks. Below are trivial example files that demonstrate the problem: XSD FILE aaa.xsd ---------------------- <?xml version="1.0" encoding="UTF-8"?>
0
1409
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
5616
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 number, and that is it. Two tables - one for the issue, one for the people (one issue can have more than one responsible person). No code - whole thing slapped together in 15 minutes. The report is set up to print the tracking number, issue,...
2
1796
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
1997
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 changes in text; - All pages are aligned > center: margin-left:auto; margin-right:auto; position:relative;
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7662
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.