[게시판] 댓글 textarea 글 작성시 자동 늘리기
2022.01.02 17:23
93
0
https://eond.com/443078
object(HotopayModel)#817 (23) { ["error"]=> int(0) ["message"]=> string(7) "success" ["variables"]=> array(0) { } ["httpStatusCode"]=> int(200) ["module"]=> string(7) "hotopay" ["module_info"]=> NULL ["origin_module_info"]=> NULL ["module_config"]=> NULL ["module_path"]=> string(52) "/home/eond/web/eond.com/public_html/modules/hotopay/" ["xml_info"]=> NULL ["module_srl"]=> NULL ["mid"]=> NULL ["act"]=> NULL ["template_path"]=> NULL ["template_file"]=> NULL ["layout_path"]=> NULL ["layout_file"]=> NULL ["edited_layout_file"]=> NULL ["stop_proc"]=> bool(false) ["user"]=> object(Rhymix\Framework\Helpers\SessionHelper)#816 (20) { ["member_srl"]=> int(0) ["user_id"]=> NULL ["user_name"]=> NULL ["nick_name"]=> NULL ["email_address"]=> NULL ["phone_number"]=> NULL ["homepage"]=> NULL ["blog"]=> NULL ["birthday"]=> NULL ["denied"]=> NULL ["status"]=> NULL ["is_admin"]=> string(1) "N" ["is_site_admin"]=> NULL ["profile_image"]=> NULL ["image_name"]=> NULL ["image_mark"]=> NULL ["signature"]=> NULL ["description"]=> NULL ["group_list"]=> array(0) { } ["menu_list"]=> array(0) { } } ["request"]=> object(Rhymix\Framework\Request)#10 (13) { ["method"]=> string(3) "GET" ["compat_method"]=> string(3) "GET" ["url"]=> string(21) "xe/443078/page/465443" ["hostname"]=> string(8) "eond.com" ["domain"]=> NULL ["protocol"]=> string(5) "https" ["callback_function"]=> string(0) "" ["_route_status":protected]=> int(200) ["_route_options":protected]=> object(stdClass)#11 (5) { ["cache_control"]=> bool(true) ["check_csrf"]=> bool(true) ["is_forwarded"]=> bool(false) ["is_indexable"]=> bool(true) ["enable_session"]=> bool(true) } ["module"]=> string(5) "board" ["mid"]=> string(2) "xe" ["act"]=> string(16) "dispBoardContent" ["args"]=> array(4) { ["document_srl"]=> string(6) "443078" ["page"]=> int(1) ["mid"]=> string(2) "xe" ["act"]=> string(16) "dispBoardContent" } } ["ajaxRequestMethod"]=> array(2) { [0]=> string(6) "XMLRPC" [1]=> string(4) "JSON" } ["gzhandler_enable"]=> bool(true) }

이번에 게시판 댓글을 에디터가 아닌 textarea로 작업했습니다.

글 작성시 자동으로 늘어나는 기능이 필요해서 찾아봤습니다.

참조1의 경우

<textarea id="newTweetContent" placeholder="What's happening?" onkeydown="resize(this)" onkeyup="resize(this)"></textarea>
<script>
function resize(obj) {
    obj.style.height = '1px';
    obj.style.height = (12 + obj.scrollHeight) + 'px';
}
</script>
<style>
textarea {
    min-height: 5rem;
    overflow-y: hidden;
    resize: none;
}
</style>

이렇게 코드가 되어있었는데 스크이 계속 생기는게 맘에 안 들어서 좀 더 찾아봤습니다.


참조2의 경우

var textEle = $('.commentEditor');
function adjustHeight() {
    textEle[0].style.height = 'auto';
    var textEleHeight = textEle.prop('scrollHeight');
    textEle.css('height', textEleHeight);
}
adjustHeight();
textEle.on('keyup', function() {
    adjustHeight();
});

좀 더 예쁘게 잘 동작하는 거 같아서 이렇게 수정했습니다.



참조

1. https://velog.io/@seungsang00/HTML-JacaScript-%ED%95%A8%EC%88%98%EB%A1%9C-textarea-%EB%86%92%EC%9D%B4-%EC%9E%90%EB%8F%99%EC%A1%B0%EC%A0%88%ED%95%98%EA%B8%B0

2. https://webisfree.com/2015-11-03/textarea-%ED%83%9C%EA%B7%B8-%EB%86%92%EC%9D%B4-%EC%9E%90%EB%8F%99%EC%9C%BC%EB%A1%9C-%EC%A1%B0%EC%A0%88%ED%95%98%EB%8A%94-%EB%B0%A9%EB%B2%95





문제점...


전체 화면 스크롤 영역 안에서일 경우는 괜찮은데,

전체 화면 스크롤보다 해당 코멘트 창이 늘어날 경우는 계속 포커싱이 해당 코멘트창으로 잡혀져버려서 아래에 타이핑되는 현재 글을 확인할 수가 없음...


ajax로 처리하면 될 거 같기도 한데 그냥 에디터로 변경해야지 ㅠ


https://velog.io/@iamjoo/figma-to-zeplin-%EA%B0%84%EB%8B%A8%ED%95%98%EA%B2%8C-%EC%95%8C%EC%95%84%EB%B3%B4%EA%B8%B0#zeplin


라이믹스는 이온디와 함께

닫기

마이페이지

로그인을 해주세요

네이버로 로그인