Player_OnlineTime/关于外链卡片代码看这.TXT

108 lines
3.1 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

如何给其他网站添加在线玩家嵌入式卡片
以下是css放到head里面也可以搞个单独的css文件放
<style>
.draggable-card {
position: fixed;
top: 20px;
left: 20px;
width: 300px;
height: 350px;
border-radius: 12px;
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
overflow: hidden;
resize: both;
z-index: 1000;
background: white;
}
.drag-handle {
background: linear-gradient(135deg, #1e88e5, #0d47a1);
color: white;
padding: 10px 16px;
cursor: move;
font-weight: bold;
user-select: none;
display: flex;
justify-content: space-between;
align-items: center;
}
.close-btn {
background: rgba(255, 255, 255, 0.2);
border: none;
color: white;
border-radius: 50%;
width: 24px;
height: 24px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
transition: background 0.2s;
}
.close-btn:hover {
background: rgba(255, 255, 255, 0.3);
}
.draggable-card iframe {
width: 100%;
height: calc(100% - 40px);
border: none;
}
</style>
以下是卡片本体直接塞进html里面
<div class="draggable-card" id="serverCard">
<div class="drag-handle">
<span>服务器状态 (可拖动)</span>
<button class="close-btn" id="closeBtn">×</button>
</div>
<iframe src="http://localhost:60048/embed" frameborder="0"></iframe>
</div>
以下是js脚本可以跟着放script里面也可以单独放个js文件
<script>
const card = document.getElementById('serverCard');
const handle = card.querySelector('.drag-handle');
const closeBtn = document.getElementById('closeBtn');
let isDragging = false;
let offsetX, offsetY;
handle.addEventListener('mousedown', (e) => {
if (e.target === closeBtn) return;
isDragging = true;
offsetX = e.clientX - card.getBoundingClientRect().left;
offsetY = e.clientY - card.getBoundingClientRect().top;
card.style.cursor = 'grabbing';
});
document.addEventListener('mousemove', (e) => {
if (!isDragging) return;
card.style.left = (e.clientX - offsetX) + 'px';
card.style.top = (e.clientY - offsetY) + 'px';
});
document.addEventListener('mouseup', () => {
isDragging = false;
card.style.cursor = '';
});
closeBtn.addEventListener('click', () => {
card.style.display = 'none';
// setTimeout(() => { card.style.display = 'block'; }, 2000); // 关闭后超时重新显示,这里暂时放着,看需求
});
</script>