且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AngularJS元素onresize事件-自定义指令

更新时间:2022-11-19 08:52:28

创建自定义指令:

app.directive("myResize", function($parse) {
    return {
        link: postLink
    };
    function postLink(scope, elem, attrs) {
        elem.on("resize", function (e) {
            var rs = $parse(attrs.myResize);
            rs(scope, {$event: e});
            scope.$apply();
        });
    }
});

用法:

<div my-resize="$ctrl.myFunction($event)">
</div>

有关更多信息,

  • AngularJS Developer Guide - Creating Custom Directives
  • AngularJS Comprehensive Directive API Reference
  • AngularJS $parse Service API Reference
  • AngularJS jqLite API Reference