{"action":"created","issue":{"url":"https://api.github.com/repos/ecomfe/esui/issues/478","labels_url":"https://api.github.com/repos/ecomfe/esui/issues/478/labels{/name}","comments_url":"https://api.github.com/repos/ecomfe/esui/issues/478/comments","events_url":"https://api.github.com/repos/ecomfe/esui/issues/478/events","html_url":"https://github.com/ecomfe/esui/issues/478","id":86994813,"number":478,"title":"Select原生控件特性支持：layer显示时选中项显示在可视区域","user":{"login":"chestnutchen","id":2787987,"avatar_url":"https://avatars.githubusercontent.com/u/2787987?v=3","gravatar_id":"","url":"https://api.github.com/users/chestnutchen","html_url":"https://github.com/chestnutchen","followers_url":"https://api.github.com/users/chestnutchen/followers","following_url":"https://api.github.com/users/chestnutchen/following{/other_user}","gists_url":"https://api.github.com/users/chestnutchen/gists{/gist_id}","starred_url":"https://api.github.com/users/chestnutchen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chestnutchen/subscriptions","organizations_url":"https://api.github.com/users/chestnutchen/orgs","repos_url":"https://api.github.com/users/chestnutchen/repos","events_url":"https://api.github.com/users/chestnutchen/events{/privacy}","received_events_url":"https://api.github.com/users/chestnutchen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-06-10T14:47:27Z","updated_at":"2015-06-12T06:21:55Z","closed_at":null,"body":"```javascript\r\n        /**\r\n         * 初始化事件交互\r\n         *\r\n         * @protected\r\n         * @override\r\n         */\r\n        Select.prototype.initEvents = function () {\r\n            this.helper.addDOMEvent(this.main, 'click', u.bind(this.layer.toggle, this.layer));\r\n            this.layer.on('rendered', u.bind(addLayerClass, this));\r\n            this.layer.on('show', u.bind(scrollSelectedItemToView, this));\r\n        };\r\n\r\n        function addLayerClass() {\r\n            this.fire('layerrendered', {layer: this.layer});\r\n        }\r\n\r\n        /**\r\n         * 展开选项时把选中的那项放到当前视野\r\n         * 和原生select看齐\r\n         */\r\n        function scrollSelectedItemToView() {\r\n            if (this.selectedIndex) {\r\n                var layerElement = this.layer.getElement(false);\r\n                var items = lib.getChildren(layerElement);\r\n                for (var i = items.length - 1; i >= 0; i--) {\r\n                    var item = items[i];\r\n                    if (i === this.selectedIndex) {\r\n                        item.scrollIntoView();\r\n                    }\r\n                }\r\n            }\r\n        }\r\n\r\n```\r\n\r\n或者其实`Layer`里边有个`centerToView`的方法，但是貌似不太好用，这个没什么把握先发个issue"},"comment":{"url":"https://api.github.com/repos/ecomfe/esui/issues/comments/111376391","html_url":"https://github.com/ecomfe/esui/issues/478#issuecomment-111376391","issue_url":"https://api.github.com/repos/ecomfe/esui/issues/478","id":111376391,"user":{"login":"chestnutchen","id":2787987,"avatar_url":"https://avatars.githubusercontent.com/u/2787987?v=3","gravatar_id":"","url":"https://api.github.com/users/chestnutchen","html_url":"https://github.com/chestnutchen","followers_url":"https://api.github.com/users/chestnutchen/followers","following_url":"https://api.github.com/users/chestnutchen/following{/other_user}","gists_url":"https://api.github.com/users/chestnutchen/gists{/gist_id}","starred_url":"https://api.github.com/users/chestnutchen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chestnutchen/subscriptions","organizations_url":"https://api.github.com/users/chestnutchen/orgs","repos_url":"https://api.github.com/users/chestnutchen/repos","events_url":"https://api.github.com/users/chestnutchen/events{/privacy}","received_events_url":"https://api.github.com/users/chestnutchen/received_events","type":"User","site_admin":false},"created_at":"2015-06-12T06:21:55Z","updated_at":"2015-06-12T06:21:55Z","body":"恩，我也觉得跳得不好，还是计算高度吧，@Justineo   `scrollIntoView`实际效果不太好使。\r\n@strwind 是想像原生控件那样，打开的时候把当前选中的放在视野里边，如果需要滚动的话。目前有可能是需要滚动才能找到我之前选的那个。"}}