many_tentacles
03-31-2010, 09:59 AM
I want to be able to move the background position of a div by 300px every time I click on a button.
So it starts at 0px then 300px on click, then 600px on click, then 900px etc etc...
I've got the following code at the moment
<!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>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<style>
#thediv
{
background-image:url(http://farm2.static.flickr.com/1320/876653257_d1e394d38e.jpg);
background-position:0 0;
height:200px;
width:300px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$('a').click(function(){
$('#thediv').css({backgroundPosition: + 300 +'px 0'});
});
});
</script>
</head>
<body>
<div id="thediv" >
<a href="javascript:;">link</a>
</div>
</body>
</html>
Thank you!
So it starts at 0px then 300px on click, then 600px on click, then 900px etc etc...
I've got the following code at the moment
<!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>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<style>
#thediv
{
background-image:url(http://farm2.static.flickr.com/1320/876653257_d1e394d38e.jpg);
background-position:0 0;
height:200px;
width:300px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$('a').click(function(){
$('#thediv').css({backgroundPosition: + 300 +'px 0'});
});
});
</script>
</head>
<body>
<div id="thediv" >
<a href="javascript:;">link</a>
</div>
</body>
</html>
Thank you!