Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7971489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:39:07+00:00 2026-06-04T07:39:07+00:00

I am facing this problem whereby during the animation, i want the fish image

  • 0

I am facing this problem whereby during the animation, i want the fish image to be moving ard in the background image (pond) and it will bounce off whenever it hit the wall or border ard the image..

Using the svg method and javascript method..

Many thanks to anyone who can help it out.. Once again, thanks for taking the time to read and help to solve this problem..

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
    <style type="text/css">

    body {
    font:76% normal verdana,arial,tahoma;
    }

    h1, h2 {
    margin:0px;
    font-size:1.2em;
    }

   p {
   margin:0px 0px 1em 0px;
   padding:0px;
   }

  .balls img {
  position:absolute;
  width:50px;
  height:50px;
  }

  </style>
  <script type="text/javascript">

  var balls = [];
  var canvasX = 485;
  var canvasY = 520;
  var timer = null;
  var m_lastX = 0;
  var m_lastY = 0;
  var M_SPACE = 24;
  var B_VMIN = 5;
  var B_VMAX = 5;
  var B_WIDTH = 13;
  var B_HEIGHT = 10;

  function rnd(n) {
    return Math.random()*n;
  }

  function rndI(n) {
    return parseInt(rnd(n));
  }

  function initBall(oBall) {
    oBall._x = rnd(canvasX);
    oBall._y = rnd(canvasY);
    oBall._vX = B_VMIN+rnd(B_VMAX)*(Math.random()>0.5?1:-1);
    oBall._vY = B_VMIN+rnd(B_VMAX);
  }

  function moveBall(oBall) {
    oBall._x += oBall._vX;
    oBall._y += oBall._vY;
    oBall.style.left = oBall._x+'px';
    oBall.style.top = oBall._y+'px';
    if ((oBall._vX>0 && oBall._x+oBall._vX+B_WIDTH>canvasX) || (oBall._vX<1 &&                           oBall._x+oBall._vX<0)) oBall._vX *= -1;
      if ((oBall._vY>0 && oBall._y+oBall._vY+B_HEIGHT>canvasY) || (oBall._vY<0 &&         oBall._y+oBall._vY<0)) oBall._vY *= -1;
    }

    function animateStuff() {
      for (var i=balls.length; i--;) {
        moveBall(balls[i]);
      }
    }

    function startAnimation() {
      if (!timer) timer = setInterval(animateStuff,20);
    }

    function stopAnimation() {
      if (!timer) return false;
      clearInterval(timer);
      timer = null;
    }

    function init() {
      balls = document.getElementById('ball-container').getElementsByTagName('img');
      for (var i=balls.length; i--;) {
        initBall(balls[i]);
      }
      //getWindowCoords();
      startAnimation();
      //document.onmousedown = mouseDown;
    }

    getWindowCoords =                 (navigator.userAgent.toLowerCase().indexOf('opera')>0||navigator.appVersion.toLowerCase().in        dexOf('safari')!=-1)?function() {
      canvasX = innerWidth;
      canvasY = innerHeight;
    }:function() {
      canvasX;
      canvasY;
    }

    </script>
    </head>
    <body>

    <h1>Interval-based animation</h1>

    <p>
     Click and drag to create more.
    </p>

    <p>
     <button onclick="startAnimation(); init();">Start</button>
     <button onclick="stopAnimation()">Stop</button>
    </p>



    <div id="ball-container" class="balls">
    <SVG xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink" id="ball-container" style="border:solid         1px #000000;width:515;height:474;">
            <image xlink:href="pond.png" x="0" y="0" width="513" height="474" />
    </SVG>
     <img src="anchovies.png" alt="" width="8" height="70" />
    </div>

    </body>
    </html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:39:08+00:00Added an answer on June 4, 2026 at 7:39 am

    Here’s an example from David Dailey showing how to do bouncing off walls in SVG.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am facing this problem here. i want to show item's name by getting
I'm facing this problem with Java. I want to get some HTML informations from
I'm facing this problem again and again, but can't find any solution (except mine,
I'm currently facing this problem with ruby on rails 3, devise and facebook oauth.
I am facing this problem upon pushing my app to Heroku: 500 internal server
I was facing this unique problem of generating a bit-mask based on the input
This is a problem am facing for long now also asked a question regarding
This is a design problem I am facing. Let's say I have a cars
I am facing the problem while inserting data this way. How to insert data
I am facing a problem while creating a static cursor in DB2. This is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.