动画不透明度在 IE 或 Opera 中不起作用
我正在尝试使用 jQuery 插件。我有这段代码可以在“灯箱”中淡入淡出:
$('#cleverbox')
.css({ opacity:0, visibility:'visible' })
.animate( {opacity:1}, 2000 );
它在 Firefox 和 Chrome 上运行良好,但在 IE(7 和 8)和 Opera 中,该元素只是出现而不是淡入。关于 SO 有很多类似的问题,但是我还没有找到有效的解决方案。
我有一个示例页面。我还遇到了一些其他问题:
- 在 Internet Explorer(7 和 8)中,第一个缩略图永远不会显示灯箱(
onload
事件永远不会触发)。 - 在 IE7 中,修复 ClearType bug 的代码不起作用。
$(this).css( 'opacity', '' )
应该删除不透明度样式(在本例中为 'filter' 属性),但它不会删除它。在 IE 的开发工具中,它仍然有style="filter: ;"
- 在 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:
- In Internet Explorer (7 and 8), the first thumbnail never displays the lightbox (the
onload
event never fires). - 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 hasstyle="filter: ;"
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过将不透明度值包装在
'
中,即$(something).animate({opacity:'1'});
?每次都对我有用。Have you tried wrapping opacity values in
'
, i.e.$(something).animate({opacity:'1'});
? Works for me everytime.感谢 Opera 社区,我在 Opera 中找到了该错误的修复程序。我有这个:
但是,如果图像位于浏览器缓存中,它永远不会触发,因为加载部分位于 onload 函数之前。解决方案是将 src 赋值移到 onload 函数下面:
I found a fix for the bug in Opera, thanks to the Opera community. I had this:
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: