Solved

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

Posted on 2014-03-14
2
427 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
ID: 39930761
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
ID: 40026713
thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

896 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

13 Experts available now in Live!

Get 1:1 Help Now