简体   繁体   English

jQuery Guillotine插件-在哪里设置高度和宽度

[英]jQuery Guillotine plugin - where to set height and width

I am using the Guillotine plugin; 我正在使用断头台插件;

jQuery Guillotine Plugin v1.3.1 http://matiasgagliano.github.com/guillotine/ jQuery Guillotine插件v1.3.1 http://matiasgagliano.github.com/guillotine/

I am testing with the demo code but trying to set the width and height. 我正在测试演示代码,但尝试设置宽度和高度。 No matter where I set the width and height the getData method fails. 无论我在哪里设置宽度和高度,getData方法都会失败。 If I remove the width and height declaration (it defaults to 400 by 300 pixels) getData works again and the control panel is updated as you click zoom etc 如果我删除了宽度和高度声明(默认为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')




});

If I set the height and width directly in the source code all is fine. 如果我直接在源代码中设置高度和宽度,那一切都很好。 Can anyone help..? 谁能帮忙..?

Thanks Rolf 谢谢罗尔夫

The issue that you are having is that the settings need to be passed in after the image has loaded. 您遇到的问题是图像加载后需要传递设置。

JavaScript: 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');
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM