javascript - firefox 使用 jQuery animate 方法和绝对位置的奇怪行为

标签 javascript jquery css firefox jquery-animate

我在使用 jQuery 的 (jQuery1.9.1) 动画方法时遇到问题。 这是我在 jsfiddle 中的代码:http://jsfiddle.net/AySas/3/ 我想使用相对百分比使 div 更宽,即:

html:
<div id="h_divCenter">
    <div id="h_divIETodos" >
        <div id="h_divIIEodoList" class="quadContent">
            <ul id="h_ulIETodoList">
                <li>itemC 3</li>
            </ul>
        </div>
    </div>

css:
#h_divCenter {
    position:absolute;
    top:0;
    left:20px;
    right:100px;
    bottom:0;
    margin: 5px;
    background: #0FF;
}
.quadContent {
    position: absolute;
    top: 41px;
    bottom: 2px;
    padding: 1px 1% 2px 1%;
    width: 98%;

}
#h_ulIETodoList,#h_ulIUTodoList,#h_ulUETodoList,#h_ulUUTodoList {
    width: 100%;
    height: 100%;
    list-style-type: none;
    overflow: auto;
}
 #h_divIETodos {
    position: absolute;
    margin: 2px;
    top: 0;
    left: 0;
    right: 50%;
    bottom: 50%;
    color: #DE3C3C;
    border: 1px solid #DE3C3C;
     -webkit-box-shadow: 0px 0px 10px #DE3C3C;
     -moz-box-shadow: 0px 0px 10px #DE3C3C;
     box-shadow: 0px 0px 10px #DE3C3C;
 }


javascript:
$('#btnTest').on("click", function(){
    $("#h_divIETodos").animate({
        right: "+=20%"
    },500);
});

并且这个div有一个绝对位置并且我已经设置了css的top,right,bottom,left属性。它在 chrome 中运行良好。但是在 firefox 中,你可以看到 div 的右边缘不能移动“20%”。有没有其他人遇到过类似的问题?非常感谢你的帮助。非常感谢!

最佳答案

您可以改为使用计算像素。按预期工作。

jsFiddle Demo

$('#btnTest').on("click", function(){

        $("#h_divIETodos").animate({

            right: "+=" + ($(this).parent().width() * 0.2) + "px"
        },500);
    });

关于javascript - firefox 使用 jQuery animate 方法和绝对位置的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18800179/

相关文章:

javascript - 在插件外调用插件函数

jquery - 当我同时有文本和变量时,如何使用 Jquery 简化 addClass 的使用

html - 如何使用 Google 跟踪代码管理器跟踪带有 span 类的 <a> 标记的点击次数?

javascript - 如何使用 setCustomValidity() API 将错误消息添加到时间表单

javascript - 在 jquery 异步 POST 调用中使用 deferred

javascript - JQuery - 将字符串转换为对象并添加 "click"事件在模块模式中不起作用

Javascript 2D 数组生成, "strange"行为

jQuery CAD 软件

javascript - 使用 text-align justify 将所有类的 text-align 更改为 javascript 左侧

javascript - 如何向我的网站添加文本?