0

I have two divs but when I hide scrollbar on one it will be bugged on both, so I need to have overflow visible in CSS. But just disable scrolling with js. Specifically for div with id chatcontent.

WebCoder
  • 62
  • 10

1 Answers1

1

You can specify the overflow styling for an element by id 'chatcontent', via the following javascript:

// Disables the overflow behaviour for chatcontent
function disableOverflowForChatcontent() {
    document.getElementById('chatcontent').style.overflow = 'hidden';
}

// Resets the overflow behaviour for chatcontent
function resetOverflowForChatcontent() {
    document.getElementById('chatcontent').style.overflow = '';
}

Ideally, you would have CSS classes defined through which you would control overflow behaviour. Supposing you had the following CSS, then your javascript would be better written as:

CSS:

.overflow-none {
   overflow:hidden;
}

JS:

// Disables the overflow behaviour for chatcontent
function disableOverflowForChatcontent() {
    document.getElementById('chatcontent').classList.add('overflow-none');
}

// Resets the overflow behaviour for chatcontent
function resetOverflowForChatcontent() {
    document.getElementById('chatcontent').classList.remove('overflow-none');
}
Dacre Denny
  • 29,664
  • 5
  • 45
  • 65
  • Rather than setting/creating inline styles, it's best to dynamically add/remove a pre-existing CSS class with `.classList.add()` or `.classList.remove()`. – Scott Marcus Oct 25 '18 at 20:38
  • 1
    @ScottMarcus yes I agree, use of pre-existing classes is preferred. Hoping the answer works within possible constraints that the OP is working in. I've just updated the answer though to capture your suggestion - thanks for the feedback :-) – Dacre Denny Oct 25 '18 at 20:43
  • But I want to have overflow: scroll; Only disabled by js – WebCoder Oct 26 '18 at 09:06
  • @WebCoder just updated answer to use `hidden` - does this work for you? – Dacre Denny Oct 27 '18 at 22:44
  • @DacreDenny when i hide overflow it get bugged. – WebCoder Oct 28 '18 at 10:26
  • @WebCoder can you give a little more detail - not sure what you mean by "it get bugged" – Dacre Denny Oct 28 '18 at 10:45
  • @DacreDenny This is chat without messages ctrlv.sk/0xAm. Max-height is not needed there. And this is chat with more messages ctrlv.sk/QXgc. And there max-height is needed but not works. – WebCoder Oct 28 '18 at 10:47
  • @WebCoder still not sure what you mean sorry. It might be more effective for you to outline your problem in more detail in a new question :-) – Dacre Denny Oct 28 '18 at 10:53
  • @DacreDenny https://stackoverflow.com/questions/53030557/max-height-doesnt-work-with-percentual-values – WebCoder Oct 28 '18 at 10:57