我正在使用以下代码。
点击div
id="popUpPane"
,div
及其子项就会出现并慢慢淡入。
再次点击div,它应该慢慢淡出然后消失。
Firefox和Chrome(也是webkit)的行为就是这样,我也知道Safari在早期版本中做过。但是,当我点击“popUpPane
”时,在Safari和Safari Mobile上都没有任何意义。
这是Safari中的一个错误,还是我可以改变以回到预期的行为?
一个补充:如果我将-webkit-transition
设置为-webkit-transition: opacity .5s ease-in-out;
,它可以正常工作,但转换只会在第一次点击时出现。在第一个之后没有过渡...如果我删除了java脚本中的opacity
- 部分,那么opo-up可以工作,但是没有过渡。
我网站上的所有其他转换都在运行。但它们都只使用opacity
而不是visibility
。
这是我的代码:
CSS:
#popUpPane {
white-space:normal;
position:fixed;
width:100%;
height:100%;
top:0;
left:0;
text-align:center;
vertical-align:middle;
visibility:hidden;
z-index:90;
}
#greyOut {
position:fixed;
width:100%;
height:100%;
top:0;
left:0;
background-color:#000;
opacity:0;
}
#popUpPicCanvas {
position:relative;
top:50%;
margin-top:-325px;
display:inline;
opacity:0;
z-index:100;
}
.fade {
-webkit-transition: all .5s ease-in-out;
-moz-transition: all .5s ease-in-out;
-o-transition: all .5s ease-in-out;
transition: all .5s ease-in-out;
}
HTML:
<div id="popUpPane" onClick="noPopUp()">
<div id="greyOut" class="fade"> </div>
<canvas id="popUpPicCanvas" width="1000" height="650" title="Bastian Beuttel" class="fade"></canvas>
</div>
使用Javascript:
var popUpPane = document.getElementById("popUpPane"),
greyOut = document.getElementById("greyOut"),
popUpPicCanvas = document.getElementById("popUpPicCanvas"),
popCanvasContext = popUpPicCanvas.getContext("2d");
var doPopUp = function(source,x,y){
var popUpPic = document.getElementById("pic"+source);
popCanvasContext.canvas.width = x;
popCanvasContext.canvas.height = y;
popCanvasContext.drawImage(popUpPic, 0, 0,x,y);
popUpPane.style.visibility = "visible";
greyOut.style.opacity = "0.7";
popUpPicCanvas.style.opacity = "1";
};
var noPopUp = function(){
greyOut.style.opacity = "0";
popUpPicCanvas.style.opacity = "0";
popUpPane.style.visibility = "hidden";
};
我希望有人可以帮助我。
感谢您的回复!
答案 0 :(得分:4)
是的,移动版Safari中存在一个错误,可以opacity
+ visibility
同时转换。
您可以使用除visibility
之外的其他内容进行修复:在您设置width
和height
至0
的情况下,将有所帮助。但是,您必须添加延迟,因此它们不会立即更改。
这是一个带有工作示例的dabblet:http://dabblet.com/gist/1642110
/**
* Delayed alternative for visibility
*/
a {
display: inline-block;
background: #888;
color:#FFF;
padding: 1em;
}
div {
width: 100px;
height: 100px;
background: lime;
transition: opacity 1s;
}
a:hover+div {
width: 0;
height: 0;
opacity: 0;
transition: width 0s 1s, height 0s 1s, opacity 1s;
}
答案 1 :(得分:0)
谢谢!
由于此bug现已从最新版本的webkit中删除,因此safari和chrome的问题已经消失。 我开始有问题,因为我的div的位置也已经过渡了所以我这样写了:
.dofade {
-webkit-transition: visibility .5s ease-in-out, opacity .5s ease-in-out;
-moz-transition: visibility .5s ease-in-out, opacity .5s ease-in-out;
-o-transition: visibility .5s ease-in-out, opacity .5s ease-in-out;
transition: visibility .5s ease-in-out, opacity .5s ease-in-out;
}