Solved

Animate two divs to switch places

Posted on 2008-06-18
2
358 Views
Last Modified: 2013-11-19
Im looking for a good site or maybe even some help on working on this.  I have "2" divs that when slected they change places, no problem.  What i am trying to do is have them animate when switching places.  Like one div heads down and then the second one goes up.  Here is what my code looks like if you need it.  Thanks for any suggestions.  Let me know if there is anything else..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<style type="text/css">

* {

margin:0px;

padding:0px;

}
 

body {

background-color:#f2f2f2;

}
 

#pictrueContainer {

width:300px;

text-align:center;

margin:10px;

border:1px solid #666666;

background-color:#FFFFFF;

padding-bottom:3px;

}
 

.pictureEven {

height:75px;

width:295px;

background-color:#CCCCCC;

border:1px solid #000000;

margin-top:3px;

text-align:left;

position:relative;

}
 

.pictureEven img {

height:75px;

width:75px;

background-color:#CCCCCC;

border-right:1px solid #000000;

border-bottom:0px;

border-left:0px;

border-top:0px;

}
 

.pictureEven img:hover {

filter:alpha(opacity=50);

-moz-opacity:.50;

opacity:.50;

cursor:pointer;

}
 

.pictureOdd {

height:75px;

width:295px;

background-color:#CCCCCC;

border:1px solid #000000;

margin-top:3px;

text-align:left;

position:relative;

}
 

.pictureOdd img {

height:75px;

width:75px;

background-color:#CCCCCC;

border-right:1px solid #000000;

border-bottom:0px;

border-left:0px;

border-top:0px;

}
 

.pictureOdd img:hover {

filter:alpha(opacity=50);

-moz-opacity:.50;

opacity:.50;

cursor:pointer;

}
 

.link_style {

position:relative;

vertical-align:top;

left:60px;

top:27px;

font-family:"Courier New", Courier, monospace;

font-size:12px;

color:#333333;
 

}
 

</style>
 

<script type="text/javascript">
 

var foo = null; // object
 

function doMove() {

  foo.style.top = parseInt(foo.style.top)+3+'px';

  setTimeout(doMove,5); // call doMove in 20msec

}
 

function init() {

  foo = document.getElementById('title'); // get the "foo" object

  foo.style.top = '0px'; // set its initial position to 0px

  foo.style.zIndex='100';

  doMove(); // start animating

}
 
 
 

var selectedCount = 0;

var firstSelectedDiv;

var secondSelectedDiv;
 

function toggleTiles(tile)

{

    switch (selectedCount)

    {

        case 0:

            selectedCount = 1;

            firstSelectedDiv = document.getElementById(tile);

            firstSelectedDiv.style.opacity = '0.5';

            break;

        case 1:

            selectedCount = 2;

            secondSelectedDiv = document.getElementById(tile);

            if ( secondSelectedDiv == firstSelectedDiv )

            {

                alert("Must Select Two images");

                selectedCount = 1;
 

            } // end: if

            else //

            {

                secondSelectedDiv.style.opacity = '0.5';

                toggleTiles(null);
 

            } // end: else

            break;

        case 2:

            var swapTileContents = firstSelectedDiv.innerHTML;

            firstSelectedDiv.innerHTML = secondSelectedDiv.innerHTML;

            secondSelectedDiv.innerHTML = swapTileContents;

            alert('swapped');

            firstSelectedDiv.style.opacity = '1.0';

            secondSelectedDiv.style.opacity = '1.0';

            selectedCount = 0;

            break;

    }

}
 
 
 
 

</script>
 
 
 

</head>
 

<body>

<div id="pictrueContainer">

<div class="pictureOdd"  id="tile0x0" onclick="toggleTiles(this.id);" > <img src="picUpload/pic1.jpg" alt="1" /> <a href="#" class="link_style">Listing_11.jpg</a> </div>

<div class="pictureEven" id="tile0x1" onclick="toggleTiles(this.id);" ><img src="picUpload/pic2.jpg" alt="2" /> <a href="#" class="link_style">Listing_21.jpg</a> </div>

<div class="pictureOdd" id="tile0x2" onclick="toggleTiles(this.id);" ><img src="picUpload/pic3.jpg" alt="3" /> <a href="#" class="link_style">Listing_22.jpg</a></div>

<div class="pictureEven" id="tile0x3" onclick="toggleTiles(this.id);" ><img src="picUpload/pic4.jpg" alt="4" /> <a href="#" class="link_style">Listing_23.jpg</a></div>

<div class="pictureOdd" id="tile0x4" onclick="toggleTiles(this.id);"><img src="picUpload/pic5.jpg" alt="5" /> <a href="#" class="link_style">Listing_24.jpg</a></div>

<div class="pictureEven" id="tile0x5" onclick="toggleTiles(this.id);"><img src="picUpload/pic6.jpg" alt="6"/> <a href="#" class="link_style">Listing_25.jpg</a></div>

<div class="pictureOdd" id="tile0x6" onclick="toggleTiles(this.id);"><img src="picUpload/pic7.jpg" alt="7" /><a href="#" class="link_style">Listing_26.jpg</a></div>

<div class="pictureEven" id="tile0x7" onclick="toggleTiles(this.id);"><img src="picUpload/pic8.jpg" alt="8" /> <a href="#" class="link_style">Listing_27.jpg</a></div>

<div class="pictureOdd" id="tile0x8" onclick="toggleTiles(this.id);"><img src="picUpload/pic9.jpg" alt="9" /> <a href="#" class="link_style">Listing_28.jpg</a></div>

<div class="pictureEven" id="tile0x9" onclick="toggleTiles(this.id);"><img src="picUpload/pic10.jpg" alt="10" /> <a href="#" class="link_style">Listing_29.jpg</a></div>
 
 

</div>

<img src="picUpload/pic11.jpg" />

</body>

</html>

Open in new window

0
Comment
Question by:chuckbeats
2 Comments
 
LVL 7

Accepted Solution

by:
ruscomp earned 500 total points
ID: 21815575
http://developer.apple.com/internet/webcontent/animation.html

..very detailed article about many different type of animations. Scroll down a little to find information for what you need.
0
 

Author Closing Comment

by:chuckbeats
ID: 31468424
Thanks that helps
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

747 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

10 Experts available now in Live!

Get 1:1 Help Now