Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery animate marginRight not working, but marginLeft works just fine

I want to make a background image scroll to the left by using the animate marginRight property which is activated by clicking a link, but its not working. The weird thing is that when I use marginLeft it works, its just backwards. Here is my test site, and here is my non working jQuery code: (Again im trying to get the background image to scroll to the left) Also please let me know if I can post anything else to make this easier on you.

<script type="text/javascript">
jQuery(document).ready(
function(){
    jQuery('#homelink').click(
        function(){
            jQuery('#SiteBackground').animate({
                marginRight : "1000px"
            },10000);
        });
});
</script>

and my html: (#SiteBackground is what I want to move to the left, and #homelink is the activator)

<img id="SiteBackground" src="/jscottsavage/media/Main/Backdrop.jpg" style="position: absolute; left: 0px; top: 0px; z-index: -1; height: 384px;">

<div id="homelink">Home</div>
like image 736
user1408440 Avatar asked Feb 14 '13 03:02

user1408440


1 Answers

I figured out a way to do this. I'm not sure if its the right/proper way but it works in Firefox, Chrome, and IE 7+ so I'm going to use it until I find a better way to do it. Basically all you do is change the 'marginRight' to a 'marginLeft', and add a - sign in front of the number, as seen below.

<script type="text/javascript">
jQuery(document).ready(
     function(){
        jQuery('#homelink').click(
    function(){
        jQuery('#SiteBackground').animate({
            marginLeft : "-1000px"
        },10000);
    });
});
</script>
like image 200
user1408440 Avatar answered Oct 02 '22 16:10

user1408440