Reputation:
what is wrong with my code? the animation is about to change width of a cell between two values. the animation doesn't work. Could you fix the script section? I'm in hurry.
<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<style type="text/css">
.tbl{display: table;}
.cell{display: table-cell;}
.container{background: url("bgs/12.png")no-repeat;width: 179px;height: 119px;}
#leftP{background: url("bgs/16.png")no-repeat right;width: 86px;height: 119px}
</style>
<script type="text/javascript">
$(document).ready(function(){
function Animation(){
$('leftP').animate({width:'48px'},"slow");
$('leftP').animate({width:'86px'},"slow","",Animation());
}
});
</script>
<title></title>
</head>
<body>
<div class="container tbl">
<div id="leftP" class="cell width"></div>
<div class="cell"></div>
</div>
</body>
</html>
Upvotes: 1
Views: 1404
Reputation: 33865
There are a number of problems with your code, I'll try to address them all:
#leftP
Here is what I believe you are looking for.
$(function () {
(function Animation(){
$('#leftP').animate({width:'48px'},"slow", function () {
$('#leftP').animate({width:'86px'},"slow","",Animation());
});
})();
});
Upvotes: 0
Reputation: 6736
Try this : you defined leftP
for animation but id must be #leftP
$(document).ready(function(){
function Animation(){
$('#leftP').animate({width:'48px'},"slow");
$('#leftP').animate({width:'86px'},"slow","",Animation());
}
Animation();
});
Upvotes: 1
Reputation: 27354
You need to call function for the first time.
function Animation()
{
$('#leftP').animate({width:'48px'},"slow");
$('#leftP').animate({width:'86px'},"slow","",Animation());
}
$(document).ready(function()
{
Animation();
});
Also You forget to define ID
in jQuery
selector.
$('#leftP')
Upvotes: 1
Reputation: 65254
you are not calling Animation()
anywhere... it won't do anything unless you call this function, Animation()
, somewhere...
Upvotes: 3