NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Feb 27, 2012 21:07:41 GMT -8
netmastertestforum.proboards.com/index.cgiHey Wormo, so I've got a code that is supposed to bring up a random image from a string and load it into a created div at a random location whenever the button is clicked. It chooses an image at random but then it stays on that one image. (So if I click it might pull up death2.jpg but then every click afterwards brings up death2.jpg.) How can I get it so it'll bring up more than just 1 random image? (click 1 brings up death1.jpg click again and it brings up death4.jpg) var img_name = new Array("death1.jpg", "death2.jpg", "death3.jpg", "death4.jpg");
var ma = img_name.length;
var rnd_nm = Math.floor(ma*Math.random()); var rnd_no = Math.ceil (rnd_nm);
var cornify_count = 0; cornify_add = function() { cornify_count += 1; var cornify_url = 'http://www.wvproductions.org/'; var div = document.createElement('div'); div.style.position = 'fixed'; var numType = 'px'; var heightRandom = Math.random()*.75; var windowHeight = 768; var windowWidth = 1024; var height = 0; var width = 0; var de = document.documentElement; if (typeof(window.innerHeight) == 'number') { windowHeight = window.innerHeight; windowWidth = window.innerWidth; } else if(de && de.clientHeight) { windowHeight = de.clientHeight; windowWidth = de.clientWidth; } else { numType = '%'; height = Math.round( height*100 )+'%'; } div.onclick = cornify_add; div.style.zIndex = 10; div.style.outline = 0; if( cornify_count==15 ) { div.style.top = Math.max( 0, Math.round( (windowHeight-530)/2 ) ) + 'px'; div.style.left = Math.round( (windowWidth-530)/2 ) + 'px'; div.style.zIndex = 1000; } else { if( numType=='px' ) div.style.top = Math.round( windowHeight*heightRandom ) + numType; else div.style.top = height; div.style.left = Math.round( Math.random()*90 ) + '%'; } var img = document.createElement('img'); var currentTime = new Date(); var submitTime = currentTime.getTime(); if( cornify_count==15 ) submitTime = 0; img.setAttribute('src',cornify_url+img_name[rnd_no]); var ease = "all .1s linear"; //div.style['-webkit-transition'] = ease; //div.style.webkitTransition = ease; div.style.WebkitTransition = ease; div.style.WebkitTransform = "rotate(1deg) scale(1.01,1.01)"; //div.style.MozTransition = "all .1s linear"; div.style.transition = "all .1s linear"; div.onmouseover = function() { var size = 1+Math.round(Math.random()*10)/100; var angle = Math.round(Math.random()*20-10); var result = "rotate("+angle+"deg) scale("+size+","+size+")"; this.style.transform = result; //this.style['-webkit-transform'] = result; //this.style.webkitTransform = result; this.style.WebkitTransform = result; //this.style.MozTransform = result; //alert(this + ' | ' + result); } div.onmouseout = function() { var size = .9+Math.round(Math.random()*10)/100; var angle = Math.round(Math.random()*6-3); var result = "rotate("+angle+"deg) scale("+size+","+size+")"; this.style.transform = result; //this.style['-webkit-transform'] = result; //this.style.webkitTransform = result; this.style.WebkitTransform = result; //this.style.MozTransform = result; } var body = document.getElementsByTagName('body')[0]; body.appendChild(div); div.appendChild(img); // Add stylesheet. if (cornify_count == 5) { var cssExisting = document.getElementById('__cornify_css'); if (!cssExisting) { var head = document.getElementsByTagName("head")[0]; var css = document.createElement('link'); css.id = '__cornify_css'; css.type = 'text/css'; css.rel = 'stylesheet'; css.href = 'http://www.cornify.com/css/cornify.css'; css.media = 'screen'; head.appendChild(css); } cornify_replace(); } }
cornify_replace = function() { // Replace text. var hc = 6; var hs; var h; var k; var words = ['Happy','Sparkly','Glittery','Fun','Magical','Lovely','Cute','Charming','Amazing','Wonderful']; while(hc >= 1) { hs = document.getElementsByTagName('h' + hc); for (k = 0; k < hs.length; k++) { h = hs[k]; h.innerHTML = words[Math.floor(Math.random()*words.length)] + ' ' + h.innerHTML; } hc-=1; } }
/* * Adapted from http://www.snaptortoise.com/konami-js/ */ var cornami = { input:"", pattern:"38384040373937396665", clear:setTimeout('cornami.clear_input()',5000), load: function() { window.document.onkeydown = function(e) { if (cornami.input == cornami.pattern) { cornify_add(); clearTimeout(cornami.clear); return; } else { cornami.input += e ? e.keyCode : event.keyCode; if (cornami.input == cornami.pattern) cornify_add(); clearTimeout(cornami.clear); cornami.clear = setTimeout("cornami.clear_input()", 5000); } } }, clear_input: function() { cornami.input=""; clearTimeout(cornami.clear); } } cornami.load();
|
|
|
Post by Wormopolis on Feb 28, 2012 1:40:41 GMT -8
this seems like a really complicated code for what it does... and what is the purpose of this code?
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Feb 28, 2012 4:46:22 GMT -8
You click the button and it creates a random image at a random location on the page. (See: www.cornify.com ) But I don't want to use their images.
|
|
|
Post by Wormopolis on Feb 28, 2012 17:55:29 GMT -8
omg.. that website goes against everything I stand for...
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Feb 28, 2012 18:42:47 GMT -8
My point exactly which is why I want better images. So is there a way to make it randomly random? Instead of one time random? I added the top part myself
var img_name = new Array("death1.jpg", "death2.jpg", "death3.jpg", "death4.jpg");
var ma = img_name.length;
var rnd_nm = Math.floor(ma*Math.random()); var rnd_no = Math.ceil (rnd_nm);
|
|
|
Post by Wormopolis on Feb 29, 2012 0:02:01 GMT -8
put the line that calls the random number into the add function
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Feb 29, 2012 9:58:05 GMT -8
That did it Wormo. Woohooo! Now to get awesome pictures of dead unicorns and dragons!
|
|
|
Post by Wormopolis on Feb 29, 2012 20:41:18 GMT -8
lol! THAT would be appropriate.
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Mar 1, 2012 5:01:15 GMT -8
Check out the effect on my testy site!
|
|
|
Post by Wormopolis on Mar 1, 2012 16:41:23 GMT -8
unicorn meat!
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Mar 1, 2012 17:15:05 GMT -8
I thought it was a particularly nice touch myself. ^_^ That and the Unicorn Blood in a can
|
|