how to create a moving div?



how to create a moving div?..

Answer / mangala

Creating the moving DIV :
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en">

<head>


<style type="text/css">
</style>

<script type="text/javascript">
function moveDiv()
{
var the_style = getStyleObject("myDiv");
var the_left = parseInt(the_style.left) + 100;
var the_top = parseInt(the_style.top) + 100;
if (document.layers)
{
the_style.left = the_left;
the_style.top = the_top;
}
else
{
the_style.left = the_left + "px";
the_style.top = the_top + "px";
}
}

function getStyleObject(objectId) {
// cross-browser function to get an object's style
object given its
if(document.getElementById &&
document.getElementById(objectId)) {
// W3C DOM
return document.getElementById(objectId).style;
} else if (document.all && document.all(objectId)) {
// MSIE 4 DOM
return document.all(objectId).style;
} else if (document.layers && document.layers[objectId]) {
// NN 4 DOM.. note: this won't find nested layers
return document.layers[objectId];
} else {
return false;
}
} // getStyleObject

// -->
</script>
</head>
<body>
<a href="#" onClick="moveDiv(); return false;">move the div</a>

<div id="myDiv"
style="position:absolute;top:50px;left:10px;"><img
src='move.gif'/>
</div>

</body>
</html>

Is This Answer Correct ?    2 Yes 3 No

Post New Answer

More JavaScript Interview Questions

What is the scope of variables in JavaScript?

0 Answers  


What is the use of window object?

0 Answers  


Please write the Code of simple javascript calculator withot eval() function

0 Answers  


How to import all exports of a file as an object.

0 Answers  


What is a function constructor?

0 Answers  






What is unobtrusive javascript? How to add behavior to an element using javascript?

0 Answers  


Difference json arrary vs json object ?

0 Answers  


What is Browser Object Model?

0 Answers  


What is the difference between null and undefined?

0 Answers  


Can any one tell me about s_objectID used for the anchor tag why it is used, what for and how to use it properly. with an example...please please......

1 Answers  


Should you use var or let?

0 Answers  


What does js stand for?

0 Answers  


Categories