I’m new to coding and hope someone could help me with my hopeless code skills. I’m trying to create a div that will animate on and off the screen on press a button. Here is what I’ve got so far…. it’s probably stupidly wrong but I guess that’s what this site is for.. here you go
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="test">Example Text</div>
<script>
function myFunction()
{
var position = test.position();
if("#test".position<0)
{
alert("hello");
$("#test").animate({
"left": 0
},1000);
}else{
$("#test").animate({
"left": -15
},1000);
});
}
</script>
</body>
</html>
This function is called when an image is clicked. My idea was to basically tell the div to animate onto the screen if it’s position value is less than 0, which I think tells it that it’s off the screen. If it doesn’t detect it’s value is offscreen, it means the div is onscreen at the moment and so it should animate away. I’d be very grateful of any help that anyone can provide. Thanks very much in advance!
Here you go.
And CSS:
Working Fiddle: http://jsfiddle.net/KeE4h/48/