动画不透明度在 IE 或 Opera 中不起作用

发布于 2024-08-16 09:28:00 字数 724 浏览 4 评论 0原文

我正在尝试使用 jQuery 插件。我有这段代码可以在“灯箱”中淡入淡出:

$('#cleverbox')
    .css({ opacity:0, visibility:'visible' })
    .animate( {opacity:1}, 2000 );

它在 Firefox 和 Chrome 上运行良好,但在 IE(7 和 8)和 Opera 中,该元素只是出现而不是淡入。关于 SO 有很多类似的问题,但是我还没有找到有效的解决方案。

我有一个示例页面。我还遇到了一些其他问题:

  1. 在 Internet Explorer(7 和 8)中,第一个缩略图永远不会显示灯箱(onload 事件永远不会触发)。
  2. 在 IE7 中,修复 ClearType bug 的代码不起作用。 $(this).css( 'opacity', '' ) 应该删除不透明度样式(在本例中为 'filter' 属性),但它不会删除它。在 IE 的开发工具中,它仍然有 style="filter: ;"
  3. 在 Opera 中,它在加载一次后就不再运行。换句话说,如果图像位于浏览器缓存中,则 onload 事件永远不会触发。

I'm experimenting with jQuery plugins. I have this code to fade in a "lightbox":

$('#cleverbox')
    .css({ opacity:0, visibility:'visible' })
    .animate( {opacity:1}, 2000 );

It works fine on Firefox and Chrome, but in IE (7 and 8) and Opera the element just appears rather than being faded in. There are a bunch of similar questions on SO but I have yet to find a solution that works.

I have an example page. I'm also having a few other problems:

  1. In Internet Explorer (7 and 8), the first thumbnail never displays the lightbox (the onload event never fires).
  2. In IE7, the code to fix the ClearType bug doesn't work. $(this).css( 'opacity', '' ) should remove the opacity style (in this case, the 'filter' property) but it doesn't remove it. In IE's dev tools it still has style="filter: ;"
  3. In Opera, it never runs after it has loaded once. In other words, if an image is in the browser cache the onload event never fires.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

七度光 2024-08-23 09:28:00

您是否尝试过将不透明度值包装在 ' 中,即 $(something).animate({opacity:'1'});?每次都对我有用。

Have you tried wrapping opacity values in ', i.e. $(something).animate({opacity:'1'});? Works for me everytime.

极度宠爱 2024-08-23 09:28:00

感谢 Opera 社区,我在 Opera 中找到了该错误的修复程序。我有这个:

var imgLoad = new Image();
imgLoad.src = linkUrl;
imgLoad.onload = function() {
    //do some stuff here
}

但是,如果图像位于浏览器缓存中,它永远不会触发,因为加载部分位于 onload 函数之前。解决方案是将 src 赋值移到 onload 函数下面:

var imgLoad = new Image();
imgLoad.onload = function() {
    //do some stuff here
}
imgLoad.src = linkUrl;

I found a fix for the bug in Opera, thanks to the Opera community. I had this:

var imgLoad = new Image();
imgLoad.src = linkUrl;
imgLoad.onload = function() {
    //do some stuff here
}

However, if the image is in the browser cache it never fires because the loading part comes before the onload function. The solution is to move the src assignment below the onload function:

var imgLoad = new Image();
imgLoad.onload = function() {
    //do some stuff here
}
imgLoad.src = linkUrl;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文