javascript - 用于模糊图像的简单 JavaScript 函数

标签 javascript jquery jquery-events pixastic

我正在使用 [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>

最佳答案

改变

img = new Image();

img = $(".blurthisimage");

更新 尝试检查图像是否加载了这个

if (img[0].complete == true) {
    Pixastic.process(img[0], "blurfast", {amount:1});
}
else {
    img.load(function () {
        Pixastic.process(img[0], "blurfast", {amount:1});
    });
}

如果你想对多张图片进行这项工作,请使用以下命令:

img.each(function(index, element)
{
    if (img[index].complete == true) {
        Pixastic.process(img[index], "blurfast", {amount:1});
    }
    else {
        img.load(function () {
            Pixastic.process(img[index], "blurfast", {amount:1});
        });
    }
});

如果这不起作用,请在您的 onload 函数中添加一个警报,以查看它是否会触发

关于javascript - 用于模糊图像的简单 JavaScript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7720422/

相关文章:

javascript - 等待渲染ace编辑器

javascript - 通过jquery删除选中的属性.model值在knockout js中未更新

javascript - 将 Jquery 对象声明为变量?

javascript - 关闭后打开 jQuery 事件监听器

javascript - 如何在 JavaScript 中不在元素上绑定(bind)点击监听器

javascript - jQuery .hover() 似乎在一段时间后为 "disappear"

javascript - 获取动态导入模块失败 :

javascript - 无法从 eventbrite api 获取纬度和经度

php - 使用 PHP 和 Javascript 的组合填充下拉列表

javascript - 如果我当前正在听一首歌,当我请求一个轨道时,Last.fm API 会发送 2 首轨道