我正在使用jCrop預覽演示來做我自己的事情。但是我遇到了一個問題。如果我使用setSelect:
加載圖像時創建默認選擇,那麼我將選擇映射到大圖像上,但它不會出現在預覽中。當jCrop加載時,我無法找到調用updatePreview函數的api處理程序。有沒有人知道如何在jCrop加載時調用這個函數?jCrop - 更新預覽onload?
jQuery(function($){
// Create variables (in this scope) to hold the API and image size
var jcrop_api, boundx, boundy;
$('#target').Jcrop({
onChange: updatePreview,
onSelect: updatePreview,
setSelect: [ 0, 0, selectWidth, selectHeight ],
aspectRatio: 1
},function(){
// Use the API to get the real image size
var bounds = this.getBounds();
boundx = bounds[0];
boundy = bounds[1];
// Store the API in the jcrop_api variable
jcrop_api = this;
});
function updatePreview(c)
{
if (parseInt(c.w) > 0)
{
var rx = 100/c.w;
var ry = 100/c.h;
$('#preview').css({
width: Math.round(rx * boundx) + 'px',
height: Math.round(ry * boundy) + 'px',
marginLeft: '-' + Math.round(rx * c.x) + 'px',
marginTop: '-' + Math.round(ry * c.y) + 'px'
});
}
};
});
好哆嗦我木材。這很煩人。感謝您指出我在正確的方向 – JasonS