Safari 中由 javascript 触发的具有不透明度和可见性的过渡
我正在使用以下代码。 通过单击 div
id="popUpPane"
,div
及其子元素应该出现并慢慢淡入。
再次单击该 div,它应该慢慢淡出,然后消失。
Firefox 和 Chrome(也是 webkit)的行为方式也是如此,我知道 Safari 在早期版本中也是如此。但众所周知,在 Safari 和 Safari Mobile 上,当我单击“popUpPane
”时,根本没有任何反应。
这是 Safari 中的错误还是我可以更改某些内容以恢复预期行为?
补充一点:如果我将 -webkit-transition
设置为 -webkit-transition: opacity .5s escape-in-out;
它工作正常,但过渡仅出现在第一个点击。第一个之后没有过渡...如果我删除 java 脚本中的 opacity
部分,opo-up 可以工作,但没有过渡。
我网站上的所有其他转换都正常。但它们都只使用不透明度
,而不使用可见性
。
这是我的代码:
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";
};
我希望有人可以帮助我。
感谢您的回复!
I'm using the following code.
By clicking on div
id="popUpPane"
, the div
and it's childs should appear and slowly fade in.
By clicking on the div again, it should slowly fade out and then disappear.
Firefox and Chrome (which is webkit too) behave that way and I know Safari did in an earlier version, too. But right know on Safari and on Safari Mobile nothing happens at all when I click on "popUpPane
".
Is this a bug in Safari or is there something I could change to come back to the intended behaviour?
One addition: If I set -webkit-transition
to -webkit-transition: opacity .5s ease-in-out;
it works fine but the transition only appears on the first click. There's no transitions after that first one... If I delete the opacity
-part in the java-script the opo-up works but there's no transition.
All other transitions on my site are working. But they all use only opacity
and no visibility
.
Here's my code:
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";
};
I hope someone can help me.
Thanks for your responds!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,移动版 Safari 中存在一个错误,即
不透明度
+可见性
同时转换。您可以使用除
可见性
之外的其他内容来修复它:在您的情况下,将宽度
和高度
设置为0
会有所帮助。但是您必须添加延迟,这样它们就不会立即改变。这是一个包含工作示例的 dabblet: http://dabblet.com/gist/1642110
Yep, there is a bug in mobile Safari with simultaneous transition for
opacity
+visibility
.You can fix it using something except for
visibility
: in your case setting thewidth
andheight
to0
would help. However you must add the delay, so they would change not instantly.Here is a dabblet with the working example: http://dabblet.com/gist/1642110
谢谢你!
由于这个错误现已从最新版本的 webkit 中删除,因此 safari 和 chrome 的问题就消失了。
我开始遇到问题,因为我的 div 的位置也发生了转换,所以我这样写:
Thank you!
Since this bug is now removed from the latest releases of webkit the problem is gone for safari and chrome.
i started to have problems since the position of my div also was transitioned so I wrote it like this: