<p id="将进酒">
君不见黄河之水天上来,奔流到海不复回。 <br>
君不见高堂明镜悲白发,朝如青丝暮成雪。 <br>
人生得意须尽欢,莫使金樽空对月。 <br>
天生我材必有用,千金散尽还复来。 <br>
烹羊宰牛且为乐,会须一饮三百杯。 <br>
岑夫子,丹丘生,将进酒,杯莫停。 <br>
与君歌一曲,请君为我倾耳听。 <br>
钟鼓馔玉不足贵,但愿长醉不复醒。 <br>
古来圣贤皆寂寞,惟有饮者留其名。 <br>
陈王昔时宴平乐,斗酒十千恣欢谑。 <br>
主人何为言少钱,径须沽取对君酌。 <br>
五花马、千金裘,呼儿将出换美酒,与尔同销万古愁。<br>
</p>
<div id="modal" class="modal">
<div class="content">
<div class="close" onclick="closeModal()">
关闭
</div>
您选中的内容为:
<p>
</p>
</div>
</div>
.modal {
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: rgba(0, 0, 0, .5);
display: none;
}
.modal.show {
display: flex;
justify-content: center;
align-items: center;
}
.modal .content {
padding: 24px;
background: white;
position: relative;
width: 31.8vw;
}
.modal .close {
position: absolute;
top: 12px;
right: 12px;
cursor: pointer;
}
window.addEventListener('mouseup', e => {
if(e.target.id === '将进酒') {
const selectedText = window.getSelection().toString()
if(selectedText !== '') {
const modal = document.getElementById('modal')
const p = modal.querySelector('p')
p.textContent = selectedText
modal.classList.add('show')
}
}
});
const closeModal = () => {
const modal = document.getElementById('modal')
modal.classList.remove('show')
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.