替换 jQuery 中的图像扩展名,即时从 .png 变为 .gif
因此,我使用 CSS3 在我的网站设计中创建侧边栏框,这效果很好而且很漂亮。使用 http://css3pie.com 在 IE 中创建效果。
再说一次,又好又花花公子。现在,我的问题来了 -
对于每个相对定位的模块,其中都有一个绝对定位的图标,将其设置为 top: -20px 以使其具有弹出效果。显然这在 IE6 中不起作用,并且它与任何 PNG 修复代码都不能很好地配合。
不过,对于 IE6 用户,我可以改用低质量的 gif,他们可以处理。
现在,我的问题是,如果用户使用 IE6,如何将 image.png 实时切换为 image.gif?
对于这个想法我还没有找到合理的解决方案。我可以使用 IE6 样式表来替换图像 - 但是在某些情况下图像不应该基于 CSS。它们应该是正确的图像。
有什么建议吗?我想要某种 jQuery 替换,但我也没有找到合理的解决方案。
So, I'm using CSS3 in order to create sidebar boxes in my site design, this works nice and dandy. Using http://css3pie.com in order to create the effect in IE.
Again, nice and dandy. Now, comes my issue -
For each relatively positioned module, there is an absolutely positioned icon within it, that is set to being top: -20px in order to give it a pop-out effect. Obviously this doesn't work in IE6, as well it doesn't play nice with any PNG fix codes.
However, for IE6 users I can switch to a low-quality gif instead, and they can deal with it.
Now, my question is, how can I manage to live-switch image.png to image.gif if the user is using IE6?
I have yet to find a reasonable solution for this idea. I could use an IE6 stylesheet to replace the images - however there are several instances where images shouldn't be CSS-based. They should be proper images.
Any suggestions? I wanted some sort of a jQuery replace, but I haven't found a reasonable solution for that either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有几种解决方案。也许最简单的方法是创建一个 jQuery 函数,当用户切换到低保真站点(通过链接)或您代表他们确定这一点(通过标题或条件注释)时调用该函数。
jQuery 函数可以利用属性选择器让生活变得更轻松。
要切换 CSS 背景,我建议使用
degrade
或类似的东西对它们进行分类,以创建 jQuery 的挂钩,然后执行与上面类似的操作。当然,您需要根据您的标记修改上面的代码,但这应该可以帮助您开始。
There are several solutions. Probably the easiest would be to create a jQuery function that was called when the user switches to the low-fi site (by link) or you determine this on their behalf (by headers or conditional comment).
The jQuery function could utilize attribute selectors to make life easier.
To switch the CSS backgrounds, I would recommend classing them with
degrade
or something of the sort to create a hook for jQuery, then doing something similar as the above.Of course, you will need to modify the code above base on your markup, but that should get you started.
这应该适用于页面上的所有非 CSS 图像:
This should work for all non-CSS images on the page:
您可以在 CSS 中使用以下 PHP 代码来了解正在使用的浏览器:
You can use this PHP code in the CSS to know what browser is being used:
您想知道如何替换元素或如何获取浏览器/版本吗?
jQuery 具备这两种功能。
获取浏览器非常简单。只需使用
jQuery.browser
。要更改图像,CSS 需要采用与
不同的方法。将所有内容设置为使用 PNG,然后执行以下操作:
Do you want to know how to replace the elements or how to get the browser/version?
jQuery has facilities for both.
Getting the browser is straightforward. just use
jQuery.browser
.To change the images would require a different approach for CSS vs.
<img>
. Set everything to use PNG's and then do something like: