使用jquery检查css的底部
我正在尝试用引号做一种提要,如果它在屏幕上下降到某个级别以下,我想重置一个引号使用jquery检查css的底部,jquery,html,css,Jquery,Html,Css,我正在尝试用引号做一种提要,如果它在屏幕上下降到某个级别以下,我想重置一个引号 function MoveDown(speed) { $('#QuoteOne').animate({ bottom: '-=100' }, speed); $('#QuoteTwo').animate({ bottom: '-=100'
function MoveDown(speed) {
$('#QuoteOne').animate({
bottom: '-=100'
}, speed);
$('#QuoteTwo').animate({
bottom: '-=100'
}, speed);
$('#QuoteThree').animate({
bottom: '-=100'
}, speed);
$('#QuoteFour').animate({
bottom: '-=100'
}, speed);
console.log($('#QuoteOne').css("bottom"));
if($('#QuoteOne').css("bottom") == '-400px' )
{
$('#QuoteOne').animate({
bottom: '= 0'
}, speed);
}
}
控制台日志显示为-400px,但我无法将其移回顶部。我缺少什么?首先,该代码将在动画完成之前执行。如果希望在动画之后执行该代码,请将其作为回调添加到
”QuoteOne
元素的animate
函数中:
$('#QuoteOne').animate({
bottom: '-=100'
}, speed, function() {
if ( $(this).css("bottom") == "-400px" )
...
});
然后将bottom:'=0'
更改为bottom:0
$('#QuoteOne').animate({
bottom: 0
}, speed);
那正是它的本来面目。你能告诉我为什么“-=”有效而“=”无效吗?@PatrickSchomburg我无法回答这个问题。这可能是因为jQuery不只是处理
=n
,而+=
和-=
在JavaScript中是有效的数学运算符。我很难链接它们。我需要三个报价块一起向下移动,然后最底部的一个在顶部淡入。您的代码修复了这一点,但仅针对一个引号div。@PatrickSchomburg您可以将选择器与逗号组合:$(''QuoteOne,'quotewo,…')。动画(…)你能告诉我为什么我的小提琴看起来不对吗?