如何将彩色 PNG 文件设为灰度?
可能的重复:
将图像转换为 HTML/CSS 中的灰度
我想要在页面加载时获取彩色 .png 图像并将其变成灰度,但是当您将鼠标悬停在图像上时,它会变回彩色,在鼠标移开时变回灰色。我已经尝试了至少 10 个不同的教程,但没有一个起作用。我需要从彩色更改为灰色,再更改为彩色,然后再更改为灰色的元素是 .photo。 http://jamestestblog3.tumblr.com/ 是我的测试网站。
我该怎么做?
Possible Duplicate:
Convert an image to grayscale in HTML/CSS
I want to take a colored .png image on page load and turns it grayscale, but then when you hover over the image, it turns back to color, and on mouseout back to gray. I've tried at least 10 different tutorials on this, but none of them worked. The element that I need to change from color to gray, back to color, and back to gray, is .photo. http://jamestestblog3.tumblr.com/ is my testing website.
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如其他人提到的,跨域问题是问题所在。不幸的是,tumblr 使用的图像域与您的博客托管的域不同。我在下面的演示中使用了第三方转换网站(http://www.maxnov.com/getimagedata) 获取图像数据。我在我的 tumblr 主题上尝试了同样的操作 (http://www.tumblr.com/theme/32199) 但最终没有使用它。
演示:http://jsfiddle.net/ThinkingStiff/vXWvz/
HTML:
脚本:
As others mentioned, the cross domain issue is the problem. Unfortunately, tumblr uses a different domain for images than the one your blog is hosted on. I used a third-party conversion site in the demo below (http://www.maxnov.com/getimagedata) to get the image data. I tried this same thing on my tumblr theme (http://www.tumblr.com/theme/32199) but ended up not using it.
Demo: http://jsfiddle.net/ThinkingStiff/vXWvz/
HTML:
Script: