scroll gutter

by Code_Garage

HTML

<div class="flex">
  <div class="card">
    <p id="text-unstable">
      0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1
    </p>
    <div class="card-footer">
      <p>
        Instable (défaut)
      </p>
      <button onClick="toggleUnstable()">
        Active-moi
      </button>
    </div>
   </div>
   <div class="card">
    <p id="text-stable">
      0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1
    </p>
    <div class="card-footer">
      <p>
        Stable
      </p>
      <button onClick="toggleStable()">
        Active-moi
      </button>
    </div>
   </div>
</div>

CSS

.flex {
  display: flex;
  gap: 10px;
  align-items: center;
}

.card {
  background-color: #3498db;
  border-radius: 5px;
  padding: 10px;
  box-shadow: 0px 0px 10px 5px rgba(0,0,0,0.1);
}
body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  font-family: Arial;
  padding-top: 20px;
}

p#text-stable, p#text-unstable {
  margin: 0;
  background-color: #2980b9;
  padding: 10px;
  color: white;
  height: 75px;
  width: 250px;
  font-size: 14px;
  font-family: sans-serif;
  font-weight: bold;
  border-radius: 3px;
  margin-bottom: 10px;
  overflow-y: auto;
}

p#text-stable {
  
  scrollbar-gutter: stable;
}

.card-footer {
  display: flex;
}

.card-footer p {
  flex: 1;
  margin: 0;
  color: white;
  font-size: 12px;
  font-family: sans-serif;
}

JavaScript

let fullStable = false;

function toggleStable(){
  if(fullStable){
  	fullStable = false;
		return document.querySelector('#text-stable').innerHTML = "0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1"
	}
  fullStable = true;
  return document.querySelector('#text-stable').innerHTML = "0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1"
}

let fullUnstable = false;

function toggleUnstable(){
  if(fullUnstable){
  	fullUnstable = false;
		return document.querySelector('#text-unstable').innerHTML = "0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1"
	}
  fullUnstable = true;
  return document.querySelector('#text-unstable').innerHTML = "0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 1"
}