When you are adding long content in CKEditor 5 classic, on scroll the toolbar bees fixed to the top in the browser window.
But I have a fixed positioned white logo area with a menu bar beneath and the toolbar appears above them:
How can I make it stay under my fixed header/navigation?
When you are adding long content in CKEditor 5 classic, on scroll the toolbar bees fixed to the top in the browser window.
But I have a fixed positioned white logo area with a menu bar beneath and the toolbar appears above them:
How can I make it stay under my fixed header/navigation?
Share Improve this question edited Oct 3, 2018 at 11:19 Reinmar 22k4 gold badges69 silver badges79 bronze badges asked Oct 3, 2018 at 7:52 BarneeBarnee 3,3998 gold badges45 silver badges56 bronze badges2 Answers
Reset to default 7I've managed to find the answer:
- You have to install
npm install --save @ckeditor/ckeditor5-ui
- Add to the config:
viewportTopOffset : Number
example:
ClassicEditor.defaultConfig = {
toolbar: {
viewportTopOffset : 50, <-- height of fixed header
items: [
'heading',
'|',
'highlight',
'|',
'bold',
'italic',
...
I needed a way to dynamically determine the bottom of a fixed navbar, so I managed to work it out this way:
</nav> <!-- bottom of navbar -->
<div id="ccms---header---end"></div> <!-- add a div to mark the bottom -->
Then I created the following function:
function getDistanceFromTop() {
let element = document.getElementById('ccms---header---end');
let distance = 0;
while (element) {
distance += element.offsetTop;
element = element.offsetParent;
}
return distance;
}
Then, in the editor initialization, I did the following:
ClassicEditor
.create( document.querySelector( '#editor' ), {
licenseKey: LICENSE_KEY, // Or 'GPL'.
plugins: [ Essentials, Paragraph, Bold, Italic, Font ],
toolbar: [
'undo', 'redo', '|', 'bold', 'italic', '|',
'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor'
],
ui: {
viewportOffset: {
top: getDistanceFromTop(),
}
}
})
.then( editor => {
window.editor = editor;
} )
.catch( error => {
console.error( error );
} );