Jquery 图像对象
Jquery Image object
我试图理解JQuery的这一部分。
$.fn.imageCrop = function(customOptions) {
//Iterate over each object
this.each(function() {
var currentObject = this,
image = new Image();
// And attach imageCrop when the object is loaded
image.onload = function() {
$.imageCrop(currentObject, customOptions);
};
// Reset the src because cached images don't fire load sometimes
image.src = currentObject.src;
});
// Unless the plug-in is returning an intrinsic value, always have the
// function return the 'this' keyword to maintain chainability
return this;
};
我无法理解的是,创建了一个新的,因此为空的 Image 对象,然后将一个 onload 方法添加到图像中,然后手动重置 image.src,以防它不触发重新加载。但是为什么它会触发重新加载呢?它只是一个空的图像对象,与任何东西都没有关系。是否以某种方式自动链接到当前对象?
这是我注释的代码,看看是否有帮助。必须将 src 设置为等待事件
//this is a jquery plugin,
//jquery plugins start this way
//so you could select $('img').imageCrop();
$.fn.imageCrop = function(customOptions) {
//Iterate over each object
this.each(function() {
//keeps the current iterated object in a variable
//current image will be kept in this var untill the next loop
var currentObject = this,
//creates a new Image object
image = new Image();
// And attach imageCrop when the object is loaded
//correct
image.onload = function() {
$.imageCrop(currentObject, customOptions);
};
//sets the src to wait for the onload event up here ^
image.src = currentObject.src;
});
// Unless the plug-in is returning an intrinsic value, always have the
// function return the 'this' keyword to maintain chainability
return this;
};
相关文章:
- 用图像而不是颜色填充对象(将图像绘制到画布上)
- JS-如何将图像对象转换为灰度并显示
- 带有内置图像对象的Canvas组件构造函数;t显示's图像
- 破坏相位器.通过按钮点击图像对象会导致TypeError
- 如何使用Phonegap将图像对象保存到Android中的文件中
- 使用Javascript对象为具有两个背景图像的DIV设置样式时出现问题
- 以编程方式将fabric-js-canvas的图像替换为hq图像,并重新计算其他对象的坐标和大小
- 如何确定使用 javascript/html 单击了哪个对象/图像
- 在画布中创建自定义图像对象
- 当图像和链接是 json 对象属性的值时,它们不起作用
- 将普通的 PNG 图像转换为 JSON 数据,然后存储到对象
- 使用javascript/jquery获取具有图像数组的对象中的所有图像
- 可点击的三个JS凸对象(点击一次即可显示图像)
- 如何在json对象中包含图像以及如何检索图像
- 缩放SVG图像以适应父对象,并在不同的实例中更改仪表颜色
- 如何将图像数组应用于Meteor.js中的模板辅助对象
- JavaScript:如何预加载<对象>图像数据?/ JavaScript 的图像与<对象>
- 将对象(图像)与底部对齐
- Javascript在网格中放置随机对象/图像
- 如何链接这两个对象(图像映射形状和复选框)