Yes, sorry, I was too hasty. I tested the book's code (at chapter_03/01_animating_css/index.html) and it seemed to work as expected with both jQuery 1.4 and 1.7, but after adding a background color to the <p> elements, it seems that even in the book's example the initial CSS is wiped before the animation happens.
On the next page of the book, it's implied that initial CSS values get wiped unless you make a modification to the script. So, instead of using padding: '15px', using padding: '+=15px' adds 15px to the original value that was set. There is an equivalent setting for removing padding from the current value: padding: '-=15px'.
I tested that on both the book's example page and yours, and it worked, except that I couldn't get the word 'padding' on its own to work. It only worked if I used paddingLeft, paddingRight etc. Darned if I know why. This is what I came up with, anyhow, for what it's worth:
Code:
<!DOCTYPE html>
<html>
<head>
<title>jquery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('p#one').animate({
paddingLeft: '-=5px',
paddingRight: '-=5px',
paddingTop: '-=5px',
paddingBottom: '-=5px',
fontSize: '30px'
}, 4000);
$('p#two').animate({
paddingLeft: '+=15px',
paddingRight: '+=15px',
paddingTop: '+=15px',
paddingBottom: '+=15px',
fontSize: '30px'
}, 4000);
});
</script>
<style>
#one {
padding: 25px;
background-color: blue;
border: solid 5px;
}
#two {
padding: 5px;
background-color: blue;
border: solid 5px;
}
</style>
</head>
<body>
<p id='one'>Home</div>
<p>Filler</p>
<p id='two'>About</div>
</body>
</html>
Anyhow, yes, I admit I'm a noob at this, but it's fun to have a try. I'll get out of your way in future and leave this to the experts.
Bookmarks