【发布时间】:2012-10-30 04:28:11
【问题描述】:
我有一个居中的 div 和 4 个其他 div - 居中 div 的每一侧都有一个。当我单击一个按钮时,每个 div 都会滑入框架并将居中的 div 推出。
它在 chrome 中运行良好,但使用 firefox 失败,让我没有来自 firebug 的错误。
Here 是我的实现,目前在 Firefox 中无法正常工作。
如您所见,在 Firefox 中,居中的 div 只是消失了,而不是滑出屏幕。使用 chrome,居中的 div 按预期滑出。
有人可以看看 firebug 并告诉我他们认为可能导致问题的原因吗?
此代码基于一个 jsfiddle,可使用 chrome 或 firefox 正常工作。
这是 jsfiddle 的代码:
这里是 html
<div id="fullContainer">
<div id="right">
</div>
<div id="left">
</div>
<div id="top">
</div>
<div id="bottom">
</div>
</div>
<div id="centerContainer">
<div id="relativeContainer">
<div id="content">
This is where your face should go. Notice that I placed it within a centering div.
This will enable the face to be absolutely positioned, and allow for you to modify
it's position when the side-bars slide in.
<div data-move="left">Open Left</div>
<div data-move="right">Open Right</div>
<div data-move="top">Open Top</div>
<div data-move="bottom">Open Bottom</div>
</div>
</div>
</div>
这里是 css
#centerContainer {
position:fixed;
top:50%;
left:50%;
width:0;
height:0;
}
#relativeContainer {
position:relative;
}
#fullContainer {
position:fixed;
width:100%;
height:100%;
top:0;
left:0;
}
#content {
position:absolute;
width:300px;
height:400px;
top:-200px;
left:-150px;
background:#BADA55;
border:1px solid #444;
padding:10px;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#content.right {
left:-250px;
}
#content.left {
left:-50px;
}
#content.bottom {
top:-300px;
}
#content.top {
top:-100px;
}
#content div {
cursor:pointer;
color:blue;
text-decoration:underline;
margin-top:15px;
text-align:center;
}
#left {
position:absolute;
top:0;
left:-125px;
height:100%;
width:100px;
background:blue;
border:1px solid #444;
padding:10px;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#left.opened {
left:0;
}
#right {
position:absolute;
top:0;
right:-125px;
height:100%;
width:100px;
background:green;
border:1px solid #444;
padding:10px;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#right.opened {
right:0;
}
#top {
position:absolute;
left:0;
top:-125px;
width:100%;
height:100px;
background:yellow;
border:1px solid #444;
padding:10px;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#top.opened {
top:0;
}
#bottom {
position:absolute;
left:0;
bottom:-125px;
width:100%;
height:100px;
background:red;
border:1px solid #444;
padding:10px;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#bottom.opened {
bottom:0;
}
这里是 javascript:
function SlideOut(element){
$(".opened").removeClass("opened");
$("#"+element).addClass("opened");
$("#content").removeClass().addClass(element);
}
$("#content div").click(function(){
var move = $(this).attr('data-move');
SlideOut(move);
});
这里是fiddle
谢谢
凯蒂
【问题讨论】:
-
试试点击额头?那是什么?在 Firefox 中,我可以单击所有 4 个链接,它们对我来说很好......
-
对不起,我指的是第二个链接 - jsfiddle 在两个浏览器上都可以正常工作
-
您的页面的 JS 与您发布的内容和小提琴不同。在小提琴(及以上)中,您使用
$("#content div").click,但在您的页面上使用$("#content div").toggle并定义一个我看不到您曾经使用过的id变量,然后调用另一个匿名函数来删除.opened到处和从#content中删除所有类。这可能会造成一些混乱。 -
@peter 至于正在开发的 id 函数,所以忽略它,但是当从内容中删除类时应该会出现动画。我将切换回更改为单击,但仍然有相同的错误。还有其他想法吗?
-
您的测试示例抛出 404。请您将其放入 JSFiddle 中,以便我们可以在无菌环境中看到它。
标签: javascript jquery html css slide