2010-11-15 62 views
0

This jQuery plugin具有连接到停止事件以下功能(我认为这是从_mouseStop事件开始):如何调用jQuery插件中的这个函数?

$('#canvas').boxer({ 
    stop: function(event, ui) { 
    var offset = ui.box.offset(); 
    ui.box.css({ border: '1px solid white', background: 'orange', padding: '0.5em' }) 
     .append('x:' + offset.left + ', y:' + offset.top) 
     .append('<br>') 
     .append('w:' + ui.box.width() + ', h:' + ui.box.height()); 
    } 
}); 

有没有一种方法,我可以调用从代码这个确切的功能(没有从输入用户),并为它提供与作为参数传递的ui对象(我有需要的变量)的等价物?我知道我可以用编程方式创建in other ways,但我很想看看我是否可以这样做,因为这会让其他事情变得更容易。谢谢阅读。

回答

0
function letsDoThis(e) { 
    $(e).boxer({ 
    stop: function(event, ui) { 
     var offset = ui.box.offset(); 
     ui.box.css({ border: '1px solid white', background: 'orange', padding: '0.5em' }) 
     .append('x:' + offset.left + ', y:' + offset.top) 
     .append('<br>') 
     .append('w:' + ui.box.width() + ', h:' + ui.box.height()); 
    } 
    }); 
} 

letsDoThis('#canvas'); 
3

尝试trigger()。你可以用它触发mouseStop事件。

​​

+0

感谢您的回答。我会在什么地方调用trigger()?我对jQuery相当陌生,无法完全理解这个插件的工作原理。 – ben 2010-11-15 05:26:04