Solved

Numbers running like slot machine. Can't make them run longer

Posted on 2014-03-14
2
424 Views
Last Modified: 2014-04-28
Hi Expert,

I've found a little script that does what I need. But I can't make it run longer than it does.

Two series of numbers that behave like slot machine. It is build in jquery and I'm not very familiar with jquery of javascript.

Al help is apreciated.

Steynsk

running example : http://83.96.174.170/test/slot.html


<html>
<head>
<style>
body{
background-color:white;

padding:0px;

margin:0px;

}



.outer {
	width:800px;
	float: none;
}



.slots {
	font-size:100px;
	font-family:arial,helvetica,sans-serif;
	overflow:hidden;
	width:100px;
	height:100px;
	border:1px solid black;
	float:right;
}



.slots .wrapper{

	margin-top:-6px;

	width:100px;

}



.slots .slot{

	width:100px;

	height:100px;

	text-align:center;

}

</style>

<script>



//note parseInt

//note stop



var opts1 = ['0','1','2','3','4','5','6','7','8','9'];

var opts2 = ['0','1','2','3','4'];









function go(){

	addSlots1($("#slots_a .wrapper"));

	moveSlots($("#slots_a .wrapper"));

	addSlots2($("#slots_b .wrapper"));

	moveSlots($("#slots_b .wrapper"));

	addSlots($("#slots_c .wrapper"));

	moveSlots($("#slots_c .wrapper"));

	addSlots($("#slots_d .wrapper"));

	moveSlots($("#slots_d .wrapper"));

}



$(document).ready(

function(){

	addSlots($("#slots_a .wrapper"));

	addSlots($("#slots_b .wrapper"));

	addSlots($("#slots_c .wrapper"));

	addSlots($("#slots_d .wrapper"));

}		

);





function addSlots1(jqo){

	for(var i = 0; i < 300; i++){

		var ctr = Math.floor(Math.random()*opts1.length);

		jqo.append("<div class='slot'>"+opts1[ctr]+"</div>");



		

	}

}



function addSlots2(jqo){

	for(var i = 0; i < 300; i++){

		var ctr = Math.floor(Math.random()*opts2.length);

		jqo.append("<div class='slot'>"+opts2[ctr]+"</div>");



		

	}

}



function moveSlots(jqo){

		var time = 6500;

		time += Math.round(Math.random()*8000);

	jqo.stop(true,true);



		var marginTop = parseInt(jqo.css("margin-top"), 10)

		

		marginTop -= (7 * 100)

		

	jqo.animate(

		{"margin-top":marginTop+"px"},

		{'duration' : time, 'easing' : "easeOutElastic"});



}

</script>
<script>
if (document.layers) {
  document.captureEvents(Event.KEYDOWN);
}

document.onkeydown = function (evt) {
  var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
  if (keyCode == 13) {
    go();
  }
  if (keyCode == 27) {
    // For Escape.
    // Your function here.
  } else {
    return true;
  }
};
</script>
</head>
<body>
<script src="jquery.1.6.4.min.js" type="text/javascript"></script>
<script src="jquery.easing.1.3.js" type="text/javascript"></script>
<div class="outer">

<div class="slots"  id="slots_a">
  <div class="wrapper" ></div>
</div>
<div class="slots"  id="slots_b">
  <div class="wrapper" ></div>
</div>
<div>
<p align="center">Push enter to start</p>
</div>
</body>

</html>

Open in new window

0
Comment
Question by:Steynsk
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
function moveSlots(jqo){

		var time = 5000; // Play around with this

		time += Math.round(Math.random()*8000);

	jqo.stop(true,true);

		var marginTop = parseInt(jqo.css("margin-top"), 10)

		marginTop -= (10000) // And play around with this

	jqo.animate(

		{"margin-top":marginTop+"px"},

		{'duration' : time, 'easing' : "easeOutElastic"});
}

Open in new window

0
 
LVL 1

Author Closing Comment

by:Steynsk
Comment Utility
thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now