jquery - 居中右侧不起作用

标签 jquery css

我正在尝试将我的盒子设置为左、上、右和下的动画,当然要居中;但右边和底部不起作用!我做错了什么吗?

$mainMenu.animate({         
    right: 0,
    top: (docHeight / 2) - 100,
    bottom: (docHeight / 2) + 100

}, 500);

谢谢

Fiddle

最佳答案

Working jsfiddle example .

您需要使用top将其发送到底部,并使用left将其发送到右侧(减去DIV height宽度)。否则 top 在底部仍然等于零并且 left 在右边仍然等于零,如果这样的话:

 $('#link1 a').click(function() {
        console.log('docHeight/2',docHeight/2)
        $mainMenu.animate({
            top: (docHeight / 2) - 100,  
             bottom: (docHeight / 2) + 100,
            left: 0           
        }, 500);
    });

    $('#link2 a').click(function() {
        $mainMenu.animate({
            top: 0,
            right: (docWidth / 2) + 100,
            left: (docWidth / 2) - 100
        }, 500);
    });

    $('#link3 a').click(function() {
        $mainMenu.animate({         
            left: (docWidth - $mainMenu.width()),
            top: (docHeight / 2) - 100,
            bottom: (docHeight / 2) + 100

        }, 500);
    });

    $('#link4 a').click(function() {
        $mainMenu.animate({           
            top: (docHeight - $mainMenu.height()),
            right: (docWidth / 2) + 100,
            left: (docWidth / 2) - 100
        }, 500);
    });

关于jquery - 居中右侧不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23229724/

相关文章:

javascript - 使用 jQuery 的 ASP.NET Telerik 控件样式

javascript - Mootools 到 jquery 对象问题

jquery - 执行JQuery jAlert插件后执行另一条指令

jquery - 使用 jQuery .change() 将变量传递给 onChange 事件

javascript - JavaScript 中使用特殊字符分割变量

jquery - jquery ui可调整大小的奇怪错误

javascript - jQuery:如何实现 slider (旋转木马)的 Controller ?

css - 如何在底部没有空格的情况下将内联 block 与文本垂直居中?

css - 使具有不同宽高比的响应图像具有相同的高度

javascript - 如果最后一个字符未完全显示,则隐藏 div 中的最后一个字符