admin管理员组文章数量:1414605
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>
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>
Share
Improve this question
edited Nov 12, 2020 at 13:22
peterh
1
asked Feb 14, 2013 at 3:42
user1408440user1408440
2175 silver badges15 bronze badges
1 Answer
Reset to default 3I 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>
本文标签: javascriptjQuery animate marginRight not workingbut marginLeft works just fineStack Overflow
版权声明:本文标题:javascript - jQuery animate marginRight not working, but marginLeft works just fine - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745186473a2646707.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论