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
Old 10-18-2008, 04:43 PM Random Image
Junior Talker

Posts: 2
Name: Steve
Trades: 0
Hi everyone

New to this forum, and not so experimented with Javascript.

I'm using this code and script to random a banner on a page. Work very fine.
-------------
CSS
#banner { margin-right: auto; margin-left: auto; width: 949px; height: 169px; clear: both; border: solid 1px #79b200;

JAVASCRIPT
<script type="text/javascript">
var el="banner";
var bgimg=new Array("test/small_ban_01.jpg", "test/small_ban_02.jpg", "test/small_ban_03.jpg", "test/small_ban_04.jpg");
var random=Math.round((bgimg.length-1)*Math.random());
var cssStr="#"+el+" { background: url("+bgimg[random]+") no-repeat top left } ";
var style=document.createElement("style");style.setAtt ribute("type","text/css");
if(style.styleSheet){style.styleSheet.cssText=cssS tr;}
else{
var cssText=document.createTextNode(cssStr);style.appe ndChild(cssText);}document.getElementsByTagName("h ead")[0].appendChild(style);
</script>

HTML
<div id="banner">
<p>RANDOM IMAGE TEST</p>
</div>
-------------

I'm looking for a way to create different DIV already with the image. and just bring the ID name into my HTML

EX:
CSS

#banner1 { background-image: url(../test/ban_01.jpg); background-repeat: no-repeat; background-attachment: scroll; background-position: left top; width: 949px; height: 169px; clear: both; margin-right: auto; margin-left: auto; border: solid 1px #79b200; }

#banner2 { background-image: url(../test/ban_02.jpg); background-repeat: no-repeat; background-attachment: scroll; background-position: left top; width: 949px; height: 169px; clear: both; margin-right: auto; margin-left: auto; border: solid 1px #79b200; }

#banner3 { background-image: url(../test/ban_03.jpg); background-repeat: no-repeat; background-attachment: scroll; background-position: left top; width: 949px; height: 169px; clear: both; margin-right: auto; margin-left: auto; border: solid 1px #79b200; }

LOOKING FOR FONCTIONNAL JAVA

var nameID = new Array("ban01", "ban02", "ban03", "ban04");
var random=Math.round((nameID.length-1)*Math.random());
var randID="#"+nameID[random];
......

HTML
<div id=randID> /* id will become ban01 or ban02 or ban03 or ban04 on refresh/reload page
<p>IMAGE TEST</p>
</div>

Any idea? Can you help ?

Thank you very much

Calimero, Montreal, Canada

Last edited by Calimero; 10-18-2008 at 04:49 PM..
Calimero is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-20-2008, 05:21 AM Re: Random Image
Brian07002's Avatar
Defies a Status

Posts: 2,140
Name: ...
Location: ...
Trades: 0
Try this Google query:

http://www.google.com/search?hl=en&q...earch&aq=f&oq=

That should yield some good results for what you want to do.
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is online now
Reply With Quote
View Public Profile
 
Old 10-25-2008, 12:49 PM Re: Random Image
Junior Talker

Posts: 2
Name: Steve
Trades: 0
Thanks Brian, But i really what to manipulate at random the Div name, instead of the image itself ... I search into google, and visit a lot of pages, but still finding only Random image manipulation, instead of random Div ID manipulation ... anyone have an Idea ?
Calimero is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Random Image
 

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.37235 seconds with 12 queries