jQuery 如何使用jquery从左到右更改css位置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19182584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change css position left to right using jquery?
提问by sun
I have a div with left
value i wanted to change it to right
side with values
我有一个带有left
值的 div,我想将其更改为right
带有值的
#check
{
left:50px;
top:20px;
position:relative;
width:100px;
height:100px;
background:rgb(100,200,0);
}
So i tried jquery like this
所以我试过这样的jquery
$(document).ready(function(){
$('#check').css('right','20px');
});
is this possible?.i tried searching but all are with the same attribute different value changes. Here is the Fiddle
这可能吗?。我尝试搜索,但都具有相同的属性不同的值更改。 这是小提琴
回答by Mark
回答by David Jones
You will need to remove the left then set the right.
您将需要删除左侧然后设置右侧。
For example:
例如:
$('#check').css('right', '20px').css('left', '');
回答by Dharmesh Thanki
Try below code.
试试下面的代码。
$(document).ready(function(){
$('#check').css({'right':'20px'});
});
回答by foxdanni
simply as it :
简单地说:
$(document).ready(function(){
$('#check').css('left','auto').css('right','20px');
});
example : http://jsfiddle.net/mwX8Z/5/
回答by Arun P Johny
回答by Ramy Alayane
found something very interesting. To animate something to the right do something like:
发现了一件很有趣的事情。要使某些内容向右移动,请执行以下操作:
$(".something").animate({
left:"",
right:"",
marginRight:"10px"
},300);
This is like setting it to right: 10px;
这就像将其设置为正确的:10px;