码迷,mamicode.com
首页 > 其他好文 > 详细

angular指令系列---多行文本框自动高度

时间:2016-06-23 20:42:47      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

angular.module(‘MyApp‘)
    .directive(‘autoTextare‘, [‘$timeout‘, function ($timeout) {
        return {
            restrict: ‘A‘,
            require: ‘^?ngModel‘,
            link: function ($scope, iElm, iAttrs, controller) {
                var nowEle = angular.element(iElm[0]);
                $timeout(function () {
                    nowEle.css(‘height‘, ‘auto‘);
                    nowEle.css(‘height‘, iElm[0].scrollHeight + ‘px‘);
                }, 100)
                iElm.on(‘input‘, function (event) {
                    nowEle.css(‘height‘, ‘auto‘);
                    nowEle.css(‘height‘, this.scrollHeight + ‘px‘);
                })
            }
        }
    }])
    

 

angular指令系列---多行文本框自动高度

标签:

原文地址:http://www.cnblogs.com/HeJason/p/5612010.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!