jQuery 断头台插件 - 在哪里设置高度和宽度
jQuery Guillotine plugin - where to set height and width
我正在使用断头台插件;
jQuery 断头台插件 v1.3.1 http://matiasgagliano.github.com/guillotine/
我正在使用演示代码进行测试,但尝试设置宽度和高度。无论我在哪里设置宽度和高度,getData 方法都会失败。如果我删除宽度和高度声明(默认为 400 x 300 像素),getData 将再次工作,并且在您单击缩放等时控制面板会更新
<script type='text/javascript'>
jQuery(function() {
var picture = $('#memberPhoto');
//SETTING THE WIDTH AND HEIGHT CAUSES GETDATA() TO STOP WORKING
//THE CONTROL PANEL DOES NOT UPDATE AND THE OUTPUT OF GETDATA IS EMPTY
//picture.guillotine({width: 250, height: 300});
// Make sure the image is completely loaded before calling the plugin
picture.one('load', function(){
// Initialize plugin (with custom event)
picture.guillotine({eventOnChange: 'guillotinechange'});
picture.guillotine('fit')
// Display inital data
var data = picture.guillotine('getData');
for(var key in data) { $('#'+key).html(data[key]); }
// Bind button actions
$('#rotate_left').click(function(){ picture.guillotine('rotateLeft'); });
$('#rotate_right').click(function(){ picture.guillotine('rotateRight'); });
$('#fit').click(function(){ picture.guillotine('fit'); });
$('#zoom_in').click(function(){ picture.guillotine('zoomIn'); });
$('#zoom_out').click(function(){ picture.guillotine('zoomOut'); });
// Update data on change
picture.on('guillotinechange', function(ev, data, action) {
data.scale = parseFloat(data.scale.toFixed(4));
for(var k in data) { $('#'+k).html(data[k]); }
console.log(data);
});
});
// Make sure the 'load' event is triggered at least once (for cached images)
if (picture.prop('complete')) picture.trigger('load')
});
如果我直接在源代码中设置高度和宽度,一切都很好。谁能帮忙..?
谢谢罗尔夫
您遇到的问题是需要在加载图像后传入设置。
JavaScript:
jQuery(function() {
var picture = $('#sample_picture');
// Make sure the image is completely loaded before calling the plugin
//SETTING THE WIDTH AND HEIGHT CAUSES GETDATA() TO STOP WORKING
//THE CONTROL PANEL DOES NOT UPDATE AND THE OUTPUT OF GETDATA IS EMPTY
//picture.guillotine({width: 250, height: 300});
picture.one('load', function(){
/*PATCH: Settings need to be passed in after the object has loaded*/
// Initialize plugin (with custom event)
picture.guillotine({
width: 250, height: 300,//<- Add plugin properties here.
eventOnChange: 'guillotinechange'
});
// Display inital data
var data = picture.guillotine('getData');
for(var key in data) { $('#'+key).html(data[key]); }
// Bind button actions
$('#rotate_left').click(function(){ picture.guillotine('rotateLeft'); });
$('#rotate_right').click(function(){ picture.guillotine('rotateRight'); });
$('#fit').click(function(){ picture.guillotine('fit'); });
$('#zoom_in').click(function(){ picture.guillotine('zoomIn'); });
$('#zoom_out').click(function(){ picture.guillotine('zoomOut'); });
// Update data on change
picture.on('guillotinechange', function(ev, data, action) {
data.scale = parseFloat(data.scale.toFixed(4));
for(var k in data) { $('#'+k).html(data[k]); }
});
});
// Make sure the 'load' event is triggered at least once (for cached images)
if (picture.prop('complete')) picture.trigger('load');
});
相关文章:
- 将“潜水高度”设置为“另一潜水高度”
- 如何将自动高度设置为svg元素
- 匹配最高选项卡的高度 - 设置幻灯片高度
- 将文档高度设置为负 100px
- 如何将宽度和高度设置为可拖动图像
- 如何将每个 td 元素的高度设置为其宽度
- 高度设置为“自动”不适用于 JS 动画
- 如何获取图像的高度并将其父高度设置为自动
- 当高度设置为 100% 时,SWF 无法填充窗口
- 根据 jQuery 中多个实例上的另一个元素高度设置高度
- 将元素高度设置为等于主体高度减去 170px
- 在JavaScript中将宽度和高度设置为百分比
- Javascript/jQuery:当最大高度设置为0时获取高度
- 将facebook画布应用程序的高度设置为等于facebook侧边栏的高度
- 如何在页面加载时将剑道网格高度设置为固定值
- 使用jQuery展开DIV时,将高度设置为auto
- 如何将嵌套的DIV高度设置为与容器相同
- 是否可以将夏季注释的角度高度设置为父高度
- 如何将标签高度设置为内容高度
- js将画布宽度/高度设置为0,并且不显示任何内容