Welcome Guest [Log In] [Register]
Search Members Calendar | Rules ZB Code Index IF Code Index
ZBCode
  • Navigation
  • ZBCode
  • Coding Support
  • Code University
  • Well, never worked with this
Hey, welcome to ZBCode, the premier coding forum for ZB. Here you fill find some of the best Invisionfree and Zetaboards Codes on the network! Unfortunately, you're sorta hovering around in guest mode at the moment; why not join in on the fun? Register an account and you can start accessing the wealth of resources we have available here. Enjoy your stay at ZBCode, and remember to tell all your friends about us; the more members, the more codes available. ;)

Interested in joining? Click here.


If you are already a member of ZBCode, feel free to login right here:

Username:   Password:
Locked Topic
Well, never worked with this; Grawr for random image placing
Tweet Topic Started: May 12 2009, 08:03 PM (158 Views)
Agent Moose May 12 2009, 08:03 PM Post #1
Member Avatar
SMF for Free Moderator

Posts:
838
Group:
Former Staff
Member
#14
Joined:
Jul 9, 2008
Well, as the description says, I'm having trouble with placing images randomly on a page when a function is executed.

I'm trying to use the Konami Code that slayer made recently, and making it so that when you type in the code, images will pop-up randomly each time you click on the mouse.

Code:
 
<script type="text/javascript">
function Random(){
var RN = new Array(); var i = 0;
RN[i++] = ["http://www.dynamicdrive.com/dynamicindex3/snow.gif"];
RN[i++] = ["http://www.dynamicdrive.com/dynamicindex3/snow2.gif"];
RN[i++] = ["http://www.dynamicdrive.com/dynamicindex3/snow3.gif"];

var x = Math.floor(Math.random() * RN.length);
var xx = Math.floor(Math.random() * window.innerHeight);
var xy = Math.floor(Math.random() * window.innerHeight);

document.getElementById("bodyarea").innerHTML += "<img style='position: absolute; left: " + xx + "; right: " + xy + ";' src='" + RN[x][0] + "' border='0' />";
};

var keyholder = [];
window.onload = function(){ document.onkeydown = keystr; }
function keystr(e){
if(!e){ e = window.event; }
tehkey = e['which'];
switch(tehkey){
case 37: keyholder.push("left"); break;
case 38: keyholder.push("up"); break;
case 39: keyholder.push("right"); break;
case 40: keyholder.push("down"); break;
case 66: keyholder.push("b"); break;
case 65: keyholder.push("a"); break;
};
var a_key = new RegExp(/up,up,down,down,left,right,left,right,b,a/i);
if(a_key.test(keyholder) == true){
document.onclick = function(){ Random(); };
};
};
</script>


So yea, if anyone can fix my problem, since I have no idea what to do, that would be great.
You could call me Troy :P | The World of Moosey | Newest Blog: SMF for Free Spam Code

Current Project: Zetaboard Javascript Tester (click on the link in the Submenu)

ZetaBoard Javascript Tester Features:
- Code Test box
- Counts how many open brackets/parentheses and closed brackets/parentheses you have in your code to make sure that your code will work.
- New: Inspect Element
Offline Profile Goto Top
 
slayer766 May 16 2009, 04:54 PM Post #2
Member Avatar
Hello all

Posts:
1,653
Group:
Distinguished Coder
Member
#12
Joined:
Jul 9, 2008
Coding language
PHP
Well it works just fine Moose but one thing you should do is that when the code is executed correctly you should return the function Random instead of if the user clicks the mouse.

Code:
 
<script type="text/javascript">
function Random(){
var RN = new Array(); var i = 0;
RN[i++] = ["http://www.dynamicdrive.com/dynamicindex3/snow.gif"];
RN[i++] = ["http://www.dynamicdrive.com/dynamicindex3/snow2.gif"];
RN[i++] = ["http://www.dynamicdrive.com/dynamicindex3/snow3.gif"];

var x = Math.floor(Math.random() * RN.length);
var xx = Math.floor(Math.random() * window.innerHeight);
var xy = Math.floor(Math.random() * window.innerHeight);

document.getElementById("bodyarea").innerHTML += "<img style='position: absolute; left: " + xx + "; right: " + xy + ";' src='" + RN[x][0] + "' border='0' />";
};

var keyholder = [];
window.onload = function(){ document.onkeydown = keystr; }
function keystr(e){
if(!e){ e = window.event; }
tehkey = e['which'];
switch(tehkey){
case 37: keyholder.push("left"); break;
case 38: keyholder.push("up"); break;
case 39: keyholder.push("right"); break;
case 40: keyholder.push("down"); break;
case 66: keyholder.push("b"); break;
case 65: keyholder.push("a"); break;
};
var a_key = new RegExp(/up,up,down,down,left,right,left,right,b,a/i);
if(a_key.test(keyholder) == true){
return Random();
};
};
</script>
Offline Profile Goto Top
 
Reid May 16 2009, 04:58 PM Post #3
Member Avatar
What? The land of the free? Whoever told you that was your enemy.

Posts:
1,790
Group:
Distinguished Coder
Member
#148
Joined:
Jul 20, 2008
Oh, the wonders of events...
The Resource Board
Offline Profile Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Code University · Next Topic »
Locked Topic

Track Topic · E-mail Topic Time: 7:48 PM Jul 10
Hosted for free by ZetaBoards · Privacy Policy