JSFiddle - React, Tailwind, and code Playground

HTML

<h1>注意JS中只是生成了一些元素,并没有绑定任何鼠标事件</h1>
<div id="wrapper">
<ul id="ul"></ul>
</div>

CSS

@keyframes header {
  to { padding: 1em 0 }
}
h1 {
  animation: header 1s alternate infinite;
  border: 1px solid;
}
#wrapper {
  transform: scale(1);
  padding-top: 1em;
}
#ul {
  height: 400px;
  overflow-y: scroll;
  overflow-x: visible;
}
li {
  position: relative;
}
li ul {
  border: 1px solid;
  padding: 2px 4px;
  position: absolute;
  left: 20px;
  top: 2px;
  list-style: none;
  padding: 0;
  margin: 0;
  white-space: nowrap;
}
li:not(:hover) ul {
  display: none;
}
.header {
  position: fixed;
  top: 0;
  left: 0;
  background: yellow;
}

JavaScript

void function main() {
	'use strict';
  const ul = document.getElementById('ul');
  for (let i=0; i<100; i++) {
  	const li = document.createElement('li');
    li.innerHTML = `${i + 1}<ul><li class="header">当前显示第${i + 1}个菜单项</li>${Array.from({ length: 5 }, (_, j) => j + 1).map(x => `<li>第 ${x} 个菜单项</li>`).join('\n')}</ul>`;
    ul.appendChild(li);
  }
}();