Safari 中由 javascript 触发的具有不透明度和可见性的过渡

发布于 2024-12-20 01:52:13 字数 2464 浏览 3 评论 0原文

我正在使用以下代码。 通过单击 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

数理化全能战士 2024-12-27 01:52:13

是的,移动版 Safari 中存在一个错误,即不透明度+可见性同时转换。

您可以使用除可见性之外的其他内容来修复它:在您的情况下,将宽度高度设置为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;
}

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 the width and height to 0 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

 /**
 * 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;
}
吃素的狼 2024-12-27 01:52:13

谢谢你!

由于这个错误现已从最新版本的 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;
}

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:

.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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文