文本框点击和焦点时改变scrollTop值

/*文本框点击和焦点时改变scrollTop值*/
function inputChangeScrollTop(obj, topNum, scrollObj) {
    if (deviceInfo.isAndroid()) {
        var $obj = obj,
            topnum = 100;
        if (topNum != undefined) {
            topnum = topNum;
        }
        if (scrollObj == undefined) {
            scrollObj = $('.content');
        }
        $obj.on('click', function (e) {
            setScrollTop($(this));
        });

        function setScrollTop(_this) {
            var $this = _this,
            setTimer = setTimeout(function () {
                var $this = _this,
                    top = $this.offset().top,
                    scrollHeight = scrollObj.scrollTop() + top - topnum;
                scrollObj.animate({ scrollTop: scrollHeight },200);
                clearInterval(setTimer);
            }, 500);
        }
    }
};

 

posted on 2016-03-22 11:57  发烧开发者  阅读(365)  评论(0编辑  收藏  举报

导航