Solved

jquery animation advice

Posted on 2014-02-24
3
703 Views
Last Modified: 2014-02-28
Hi all,

I want to create a small semi-interactive effect on my site.

Basically I have a number of balloon pngs.

I want to create instance off the bottom of the screen and animate them up across until the are out of bounds at the top where I destroy them.

I would like to have them animate some what randomly and want to try and avoid them being spawned in the same place?

I'm just after some avice on how to do this.
0
Comment
Question by:flynny
[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
3 Comments
 
LVL 57

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39882541
Here is something I knocked together. Animation is achieved with one line of chained JQuery calls.

<!doctype html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
var startheight = 0;
var startwidth = 0;
$(function() {
  startheight = $(window).height() + 100;
  startwidth = $(window).width() - 100;
  setTimeout('balloon()', 500);
});

function randomMinMax(min,max)
{
    return Math.floor(Math.random()*(max-min+1)+min);
}

function balloon()
{
  var timeout = randomMinMax(250,750);
  var animationspeed = randomMinMax(2500,10000);
  var leftspace = randomMinMax(100, startwidth);
  var pos = '0px -' + (randomMinMax(0,4) * 100) + 'px';
  $('#balloons')
    .append( 
      $('<div/>')
        .addClass('balloon')
        .css({top: startheight + 'px', left: leftspace + 'px', backgroundPosition: pos})
        .animate(
          {top : '-100px'}, 
          animationspeed,
          function() {
            $(this).remove();
          }
        )
    );
  
  setTimeout('balloon()', timeout);
}

</script>
<style type="text/css">
body, html, #balloons {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
div.balloon {
  width: 100px;
  height: 75px;
  background-image: url(images/balloons.png);
  background-position: 0 0;
  background-repeat: no-repeat;
  position: absolute;
  top: -9999px;
  left: 90px;
}
</style>
</head>
<body>
<div id="balloons">
</div>
</body>
</html>

Open in new window

Working sample here
balloons.png
0
 

Author Closing Comment

by:flynny
ID: 39894269
many thanks didnt expect code, it really helped.
0
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 39894423
You are welcome - thanks for the points.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javascript delete path 7 42
Call a VB.net function in Javascript 6 49
Horizontal Full Calendar using php 5 40
Secure registration PHP 7 37
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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

737 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