Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-03-14
2
Medium Priority
?
449 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 2000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

661 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