[에디터] CKeditor4.x 에디터 툴바 고정하기

페이지 정보

yadolee 루루아빠 4,217 1 2016.05.24 01:32:05

본문

CKeditor4.x 에디터 사용시 본문이 길 경우 툴바 메뉴를 사용하기 위해 마우스 휠을 사용해야 하는 수고스러움이 있다.
그 수고스러움을 덜어보자

1. 그누보드5/plugin/CKeditor4.x/config.js 를 열어 소스 가장 하단 }; 바로 위쪽에 다음 소스를 추가한다.

window.CKEDITOR.on('instanceReady', function () {
    var toolbar = document.getElementsByClassName('cke_top').item(0),
                  boxTop = toolbar.getBoundingClientRect().top,
                  offsetTop = 45; // toolbar offset top

    window.addEventListener('scroll', function () {
        window.requestAnimationFrame(function () {
            var scrollTop =document.body.scrollTop;
            if ((scrollTop + offsetTop) > boxTop) {
                toolbar.style.top = scrollTop + offsetTop - boxTop + 'px';
            } else {
                toolbar.style.top = 0;
            }
        });
    }, false);
});
2. 동일 폴더 contents.css 를 열어 다음 스타일을 추가한다.


.cke_top {
    position: relative;
    top: 0;
    left: 0;
    right: 0;
    will-change: top;
}

추천인
  • 추천해 주세요
yadolee
6
루루아빠 - 회원등급 : 최고관리자 - 포인트 : 1,345,458
레벨 101
경험치 1,517,683

Progress Bar 8.86%

- 가입일 : 2015-03-04 03:24:54
- 서명 : KNOW YOUR LIMITS BUT NEVER STOP TRYING TO EXCEED THEM !!
- 자기소개 : 루루의 자랑 루루아빠랍니다~~

댓글1

루루아빠님의 댓글

yadolee
루루아빠 글쓴이 2016.06.01 01:35
상기 소스를 이용하는 것보다 플러그인을 활용하는 게 더 효과적이였다. http://ckeditor.com/addon/fixed 상기 애드온을 다운 받아 소스를 plugin.js 를 아래 소스롤 덮어 씌워 사용하자



CKEDITOR.plugins.add( 'fixed', {
    init: function( editor ) {
      editor.on('instanceReady', function (readyEvent) {
        if (CKEDITOR.toolbarFixer == undefined) {      // To prevent double activation - event listener and its handler should be set only once
          CKEDITOR.toolbarFixer = function toolbarFixerF(event) {
            for(var i=0; i document.body.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;

              toolbar.style.width = content.offsetWidth + "px";
              toolbar.style.top = "0px";
              toolbar.style.left = "0px";
              toolbar.style.right = "0px";
              toolbar.style.margin = "0 auto";
              toolbar.style.boxSizing = "border-box";

              if (editor.offsetTop <= scrollvalue && (editor.offsetTop + editor.offsetHeight) > (scrollvalue + toolbar.offsetHeight + 100)) {
                toolbar.style.position = "fixed";
                content.style.marginTop = toolbar.offsetHeight + "px";
              } else {
                toolbar.style.position = "relative";
                content.style.marginTop = "0px";
              }
            }
          };
          CKEDITOR.toolbarFixer.ckeRootNodes = [];
          window.addEventListener('scroll', CKEDITOR.toolbarFixer, false);
        }
        CKEDITOR.toolbarFixer.ckeRootNodes.push(readyEvent.editor.container.$);
        readyEvent.editor.container.$.getElementsByClassName('cke_top').item(0).style.zIndex = 100;    // For codemirror plugin compatibility
      });
    }
});

Total 2411 페이지

제목 글쓴이 날짜 조회 추천
에디터  댓글+1 CKEditor 4.x 툴바에서 소스 글자 지우기 shadow2fox 2025.05.04 582 2
에디터  댓글+2🏆 CKEditor 4.x 버전 체크로 인한 콘솔 에러 해결하기 shadow2fox 2023.12.24 2.0k 3
에디터  댓글+2🏆 CKEditor 4.x 링크 이용 시 rel 속성 noopener, noreferrer, nofollow 자동으로 삽입하기 shadow2fox 2023.10.15 3.3k 2
에디터  댓글+1🏆 SmartEditor2 주소 자동 링크 기능 끄기 shadow2fox 2020.04.06 2.6k 1
에디터  댓글+1🏆 SmartEditor2 포토 업로더 모바일에서 사진 순서 정렬하기 shadow2fox 2020.04.05 2.7k 1
에디터  🏆 [CKEDITOR] Error code: filetools-response-error 해결하기 shadow2fox 2019.09.19 3.6k 0
에디터  🏆 [CKEDITOR] Error code: editor-element-conflict 해결하기 shadow2fox 2019.08.27 4.7k 0
에디터  댓글+1🏆 CKEditor 4.x 에서 i 태그(Font Awesome) 사라지는 문제 해결하기 루루아빠 2017.02.25 3.8k 1
에디터  🏆 CKeditor4.x 글 작성시 스페이스 공란이 &nbsp; 로 자동으로 변경되는 문제 해결 루루아빠 2016.11.06 3.3k 1
에디터  🏆 CKeditor4.x 에디터 툴바 고정후 스크롤시 firefox에서 가로폭 늘어나는 문제 해결 루루아빠 2016.09.18 3.7k 0
에디터  🏆 CKeditor4.x Toolbar Icon 순서 입맛대로 정렬하기 루루아빠 2016.06.04 3.7k 0
에디터  댓글+1🏆 🚩 CKeditor4.x 에디터 툴바 고정하기 루루아빠 2016.05.24 4.2k 0
에디터  🏆 CKeditor4.x 이미지 첨부시 에디터에 맞게 반응형으로 만들기 루루아빠 2016.05.21 4.8k 0
에디터  댓글+1🏆 CKeditor 4.x 소스 보기시 자동으로 공백 태그(&nbsp;) 추가되는 문제 해결하기 루루아빠 2016.01.08 8.1k 1
에디터  🏆 Smarteditor2 링크 무조건 새창(_blank)으로 띄우기 루루아빠 2015.05.31 3.9k 0
에디터  🏆 CKeditor4.x 링크 기본값 새창(_blank)으로 변경하기 루루아빠 2015.05.31 4.6k 0
에디터  댓글+1🏆 에디터상에서 이미지 가운데 정렬 루루아빠 2015.05.23 3.8k 0
에디터  🏆 SmartEditor2 사진 업로드 사용하지 않기 루루아빠 2015.05.16 4.1k 0
에디터  🏆 CKeditor4.x 소스 온전하게 보여주기 루루아빠 2015.05.06 4.0k 1
에디터  🏆 CKeditor4.x 에 폰트 추가하기 루루아빠 2015.04.28 3.6k 0
에디터  🏆 CKeditor4.x 에디터 상 엔터를 쉬프트+엔터 바꾸기 루루아빠 2015.04.24 3.7k 0
에디터  🏆 smarteditor2 로 사진 첨부시 에디터 크기에 맞게 리사이즈 루루아빠 2015.04.23 3.7k 0
에디터  댓글+1🏆 smarteditor2 사진 첨부시 절대경로를 상대경로로 변경하기 루루아빠 2015.04.18 4.9k 0
에디터  🏆 smarteditor2를 이용하여 이미지 업로드시 이미지 위에 타이틀 팝업창 없애기 루루아빠 2015.04.11 3.8k 0