简单的 JavaScript 函数来模糊图像
我正在使用 [jQuery 插件][1] 使用以下代码创建模糊图像:
$(document).ready(function(){
var img = new Image();
img.onload = function() {
Pixastic.process(img, "blurfast", {amount:1});
}
document.body.appendChild(img);
img.src = "image.jpg";
});
我如何重写它,而不是创建图像,我可以将其分配给 < img class="blurthisimage" >
?
更新:
新代码仍然无法工作:
<img src="image.jpg" class="blurthisimage" />
<script type="text/javascript">
$(document).ready(function(){
var img = $(".blurthisimage");
img.onload = function() {
Pixastic.process(img, "blurfast", {amount:1});
}
});
</script>
I'm using a [jQuery plugin][1] to create a blur an image with the following code:
$(document).ready(function(){
var img = new Image();
img.onload = function() {
Pixastic.process(img, "blurfast", {amount:1});
}
document.body.appendChild(img);
img.src = "image.jpg";
});
How can I rewrite this so than rather than creating the image I can just assign it to < img class="blurthisimage" >
?
UPDATE:
New code still not working:
<img src="image.jpg" class="blurthisimage" />
<script type="text/javascript">
$(document).ready(function(){
var img = $(".blurthisimage");
img.onload = function() {
Pixastic.process(img, "blurfast", {amount:1});
}
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改
将
img = new Image();
为
img = $(".blurthisimage");
更新
请尝试检查图像是否已加载,
如果您想在多个图像上使用此功能,
请使用以下命令:如果这不起作用,请在您的
onload
函数中添加一个警报以查看是否可以甚至火灾Change
img = new Image();
to
img = $(".blurthisimage");
UPDATE
Try checking to see if the image is loaded with this
if you wanted to have this work on multiple images use the following:
If that doesn't work add an alert to inside your
onload
function to see if it even firesimg.onload
函数是否受到攻击?如果代码甚至没有进入该函数,可能是因为您在 jQuery 的.ready()
函数中实例化了.onload
代码,该代码会等待页面加载运行代码(请参阅ready()
文档)。当函数被实例化时,图像已经被加载,因此该事件永远不会触发。Is the
img.onload
function getting hit? If the code is not even getting into the function it might be because you instantiate the.onload
code in jQuery's.ready()
function which waits until the page is loaded to run the code (see theready()
documentation) . By the time the function gets instantiated the image has already been loaded so that event will never fire.