代码实现:
document * { margin: 0; top: 0; } .login-btn { width: 50px; height: 50px; line-height: 50px; font-size: 16px; text-align: center; margin: 100px auto; background-color: #1E1E1E; color: white; border-radius: 50%; } .login-btn:hover { cursor: pointer; background-color: #323233; box-shadow: 3px 3px 10px rgba(0, 0, 0, .3); } .bg { display: none; width: 100%; height: 100%; position: fixed; top: 0; left: 0; background-color: rgba(0, 0, 0, .4); } .login { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 300px; height: 200px; background-color: #1E1E1E; box-shadow: 4px 4px 15px rgba(0, 0, 0, .3); } .hd { position: relative; width: 100%; height: 26px; background-color: #323233; } .hd:hover { cursor: move; } .close { position: absolute; top: 3px; right: 5px; width: 20px; height: 20px; background-color: red; text-align: center; line-height: 20px; border-radius: 50%; box-shadow: 0 0 5px rgba(0, 0, 0, .7) inset; } .close:hover { background-color: yellow; cursor: pointer; } 点击 ×
实现效果:
点击点击按钮,弹出对话框。
按住对话框顶部并移动,实现拖动效果。
点击对话框右上角×,关闭对话框。
到此这篇关于Javascript实现拖动对话框效果的实现代码的文章就介绍到这了,更多相关js拖动对话框内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!



