我开始学习jQuery.我编写了一个代码,它将通过调用存储在数组中的函数来循环给定元素的位置.这适用于此代码:
<script type="text/javascript">
$(document).ready(function(){
$('#right_column').css({zIndex:1000, position: 'absolute', right: 0, top:200 });
$('body').css({overflow:'hidden'});
var funcs = new Array(
function(o){
$(o).animate({right: 0, top:200}, 1000);
},
function(o){
$(o).animate({top: 0},1000);
},
function(o){
$(o).animate({right: 300},1000);
},
function(o){
$(o).animate({right: 300, top:200},1000);
}
);
var flip=0;
$('#right_column').click(function self(){
funcs[++flip % funcs.length]('#right_column');
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
但如果我改变这样的位置参数
var funcs = new Array(
function(o){
$(o).animate({right: 0, top:200}, 1000);
},
function(o){
$(o).animate({top: 0},1000);
},
function(o){
$(o).animate({left: 0},1000);
},
function(o){
$(o).animate({right: 300, bottom:0},1000);
}
);
Run Code Online (Sandbox Code Playgroud)
它打破了.
我假设,补充参数(顶部< - >底部;左< - >右)干扰,就像在普通css中一样.
所以我的问题是:如何将css参数重置为undefined?
编辑
animate似乎无法处理auto.它没有改变行为.随着css()它工作.
var funcs = new Array(
function(o){
$(o).css({right:0, bottom:0,left:'auto', top:'auto'})
console.log('funcs 0');
},
function(o){
$(o).css({top:0, right:0, left:'auto', bottom:'auto'})
console.log('funcs 1');
},
function(o){
$(o).css({left:0, top:0, right:'auto', bottom:'auto'})
console.log('funcs 2');
},
function(o){
$(o).css({right:'auto', top:'auto',left:0, bottom:0})
console.log('funcs 3');
}
);
Run Code Online (Sandbox Code Playgroud)
css({...:'auto'})在animate()销毁(原因)动画之前/之后运行
还有其他提示吗?
重置这些值会将其更改为"自动"
top: auto;
left: auto;
right: 0px;
bottom: 0px;
Run Code Online (Sandbox Code Playgroud)
编辑:
你可以添加"目标".
<div id="top" style="position:absolute;left:0;top:0"></div>
<div id="bottom" style="position:absolute;left:0;top:auto;bottom:0px"></div>
Run Code Online (Sandbox Code Playgroud)
现在,您可以使用目标值作为动画:
$("#bottom").offset().top
$("#bottom").offset().left
Run Code Online (Sandbox Code Playgroud)
动画:
$(o).animate({ top : $("#bottom").offset().top, left : $("#bottom").offset().left });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2282 次 |
| 最近记录: |