LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-10-2011, 12:05 PM   #1
dickgregory
Member
 
Registered: Oct 2002
Location: Houston
Distribution: Arch, PCLinuxOS, Mint
Posts: 257

Rep: Reputation: 34
[HTML/CSS/Javascript] Moving background image


I am trying to set up a webpage banner that contains a background of the sky and clouds. Superimposed in the center will be an image of an airplane with a transparent background.

I want the sky to scroll continuously to the left behind the airplane. I am having problems with the background not being visible, not moving as expected, the airplane not being visible, and just disappointment in general.

I think the background of a div will not be visible if there are no internal contents because it will be sized to zero. So I introduced another transparent image to force the size of the main div. Still no joy.

Here is my code. Note that I don't have my timers set up yet, just a button to test background movement.

Code:
<!DOCTYPE html>

<html>

<head>
  <title>Texas Flight</title>
  <link rel=Stylesheet type="text/css" href="static/css/styles.css" />

  <script>
    currpos = 0;
    function movesky(distance)
    {
      alert("distance = " + distance);
      currpos += distance;
      alert("position = " + currpos);
      document.getElementById("sky").style.backgroundPositionX = currpos + "px";
    }
  </script>

</head>

<body>

<div id='sky' class='skyslide' background-image='static/image/wideclouds01b.jpg'>
  <img src="static/image/transparent150.png" />
  <img id="planesprite" src="static/image/DiamondDA20-A1.png"/>
</div>

<input type='button' onclick="movesky(10);" value="move it"></input>

</body>
</html>
Code:
body
{
}

#sky
{
  display: block;
  position: relative;
  height: 150px;
  min-width: 100%;
  max-width: 100%;
  text-align: center;
  background-image: url('static/image/wideclouds01b.jpg');
  background-repeat:repeat-x;
  overflow: hidden;
}

#planesprite
{
  position: relative;
  top: -170px;
}

Any help is welcome, including insults for stupid techniques .
 
Old 06-10-2011, 12:26 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,246

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
Why not just render the animation as a Flash movie?

If you don't want to use Flash, then you are almost certainly better off doing the animation in a Canvas object.

Last edited by dugan; 06-10-2011 at 12:30 PM.
 
Old 06-10-2011, 06:57 PM   #3
dickgregory
Member
 
Registered: Oct 2002
Location: Houston
Distribution: Arch, PCLinuxOS, Mint
Posts: 257

Original Poster
Rep: Reputation: 34
Thanks dugan. I hadn't thought of using a canvas. I'm still very new to html5 and still have a lot to learn. I'll do some more homework before I ask any more questions because I don't expect others to do my grunt work for me.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS - Is there a way to put several lines of HTML into one line using CSS? Chronothread Programming 12 01-05-2011 06:06 AM
[SOLVED] Really good web site for learning HTML CSS Javascript etc. jlinkels Programming 1 07-25-2010 07:51 PM
The best HTML/CSS/JavaScript book? christianunix Linux - Newbie 1 04-03-2009 10:18 PM
eclipse 3.4 html css javascript editor plugin manuleka Linux - Software 0 03-30-2009 02:16 PM
HTML/CSS/JS: Problem with <p> not having an absolute position with CSS. RHLinuxGUY Programming 7 03-03-2007 12:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration