jquery - 使用 jquery 检查 css 底部

标签 jquery html css

我正在尝试使用报价进行某种提要,并且如果报价低于屏幕上的特定水平,我想重置报价。

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);

关于jquery - 使用 jquery 检查 css 底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28028085/

相关文章:

javascript - 使用克隆 jQuery 时不生成 HTML 选择下拉值

javascript - 我的 Bootstrap Modal ANCHOR 在菜单(导航栏)的行元素中不起作用

html - 用另一个元素包裹时,CSS 动画无法正常工作

html - div 和 span 在一起

css - Sass 会取代 Css 吗?

css - 将水平导航栏的其余部分设置为另一种颜色?

javascript - 单击切换多个目标

javascript - 当用户单击链接到下一页的那些元素时,如何在网页中显示灰色并显示加载?

javascript - 如何确保Else语句保留在同一个html页面上?

html - 将 90 度翻转的 div 与常规水平 div 对齐