Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Random position of multiple divs
Old 02-20-2008, 10:46 AM Random position of multiple divs
Junior Talker

Posts: 2
Name: Ben
Trades: 0
Hi everyone.....

I am trying to have multiple divs load in random positions...... I have managed to get one div to work
I am not sure what to add to the javascript to make it work.....

this is my script below......


---------------------------------------------------------------------------------------------------
<html>
<head>
<title>
Random Start Position Test
</title>

<style>
#myobj {background-color:#cccccc;visibility:hidden;position:absolute}
</style>

<script>
// Cross Browser DOM
var aDOM = 0, ieDOM = 0, nsDOM = 0; var stdDOM = document.getElementById; if (stdDOM) aDOM = 1; else {ieDOM = document.all; if (ieDOM) aDOM = 1; else { var nsDOM = ((navigator.appName.indexOf('Netscape') != -1) && (parseInt(navigator.appVersion) ==4)); if (nsDOM) aDOM = 1;}}
function xDOM(objectId, wS) { if (stdDOM) return wS ? document.getElementById(objectId).style: document.getElementById(objectId); if (ieDOM) return wS ? document.all[objectId].style: document.all[objectId]; if (nsDOM) return document.layers[objectId]; }

// More Object Functions
function setObjVis(objectID,vis) {var objs = xDOM(objectID,1); objs.visibility = vis;}
function moveObjTo(objectID,x,y) {var objs = xDOM(objectID,1); objs.left = x; objs.top = y;}

// Browser Window Size and Position
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement.scroll Left? document.documentElement.scrollLeft:document.body. scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement.scroll Top? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0; }

// Random Position Script
var xxx = Math.floor(Math.random()* (pageWidth()-230));
var yyy = Math.floor(Math.random()* (pageHeight()-50));

function start() {var x = (posLeft()+xxx) + 'px'; var y = (posTop()+yyy) + 'px'; moveObjTo('myobj',x,y); setObjVis('myobj','visible');}
window.onload = start;
window.onscroll = start;
</script>
</head>
<body>
<div id="myobj">This is a web page object.</div>
</body>
</html>


---------------------------------------------------------------------------------------------------



I hope u can help!


ben

d-e-p-i-c-t dot com
benreynolds4 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-25-2008, 06:18 PM Re: Random position of multiple divs
Experienced Talker

Posts: 46
Trades: 0
What line number is the error on? (I don't really feel like going through all your code )
__________________

Please login or register to view this content. Registration is FREE
-> Home of the crasher squirrel
jeff_oneil is offline
Reply With Quote
View Public Profile Visit jeff_oneil's homepage!
 
Reply     « Reply to Random position of multiple divs
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10440 seconds with 12 queries