【发布时间】:2020-11-26 12:37:56
【问题描述】:
有人知道我如何制作这个模态弹出表单,可移动/可拖动吗?
理想情况下,我希望它最初“出现”在屏幕的右上角或右下角 - 滑入式动画也很棒 - 但用户随后能够移动/拖动它到另一个位置(取决于屏幕大小/分辨率等,它可能会覆盖父页面上的某些内容)我怀疑现有 CSS 中的某些内容将其“锁定”到位。
(如果有人知道我如何使弹出窗口最初“滑入”而不是简单地出现,则加分 - 目前在函数内使用简单的 display:none / display:block 开关 - 但这不是必需的......)
谢谢!
function openFeedbackForm() {
document.getElementById("popup-feedback").style.display = "block";
}
function closeFeedbackForm() {
document.getElementById("popup-feedback").style.display = "none";
}
$(document).ready(function() {
openFeedbackForm();
});
th {
padding: 12px;
margin: 12px;
}
td {
padding: 12px;
margin: 12px;
}
.switch-field {
display: inline;
margin-bottom: 36px;
overflow: hidden;
}
.switch-field input {
position: absolute !important;
clip: rect(0, 0, 0, 0);
height: 1px;
width: 1px;
border: 0;
overflow: hidden;
}
.switch-field label {
background-color: #e4e4e4;
color: rgba(0, 0, 0, 0.6);
font-size: 14px;
line-height: 1;
text-align: center;
padding: 8px 16px;
margin-right: -1px;
border: 1px solid rgba(0, 0, 0, 0.2);
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1);
transition: all 0.1s ease-in-out;
opacity: 0.8;
}
.switch-field label:hover {
cursor: pointer;
opacity: 1;
}
.switch-field input:checked+label {
background-color: #a5dc86;
box-shadow: none;
}
.switch-field label:first-of-type {
border-radius: 4px 0 0 4px;
}
.switch-field label:last-of-type {
border-radius: 0 4px 4px 0;
}
{
box-sizing: border-box;
}
/* The popup form - hidden by default */
#popup-feedback {
display: none;
position: absolute;
bottom: 0;
right: 15px;
border: 3px solid #f1f1f1;
z-index: 9;
}
#popup-feedback-header {
font-size: 16px;
font-weight: bold;
font-family: Calibri;
padding: 10px;
cursor: move;
z-index: 10;
background-color: #2196F3;
color: #fff;
}
/* Add styles to the form container */
.form-container {
width: 500px;
padding: 10px;
background-color: white;
}
/* Full-width input fields */
.form-container textarea[type=feedbackComments] {
width: 93%;
padding: 15px;
margin: 5px 0 22px 0;
border: none;
background: #f1f1f1;
font-size: 14px;
font-family: Calibri;
}
/* When the inputs get focus, do something */
.form-container textarea[type=feedbackComments]:focus {
background-color: #ddd;
outline: none;
}
/* Set a style for the submit/login button */
.form-container .btn {
font-size: 16px;
font-weight: bold;
background-color: #4CAF50;
color: white;
padding: 16px 20px;
border: none;
cursor: pointer;
width: 100%;
margin-bottom: 10px;
opacity: 0.8;
}
/* Add some hover effects to buttons */
.form-container .btn:hover {
opacity: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<div id="popup-feedback">
<div id="popup-feedback-header">Please give us your feedback!</div>
<form action="/action_page.php" class="form-container">
<table>
<tr>
<td>Did this resolve your issue?</td>
<td>
<div class="switch-field" name="resolutionFeedback">
<input type="radio" id="radio-helpful-yes" name="switch-helpful" value="yes">
<label for="radio-helpful-yes">Yes</label>
<input type="radio" id="radio-helpful-no" name="switch-helpful" value="no">
<label for="radio-helpful-no">No</label>
</div>
</td>
</tr>
<tr>
<td>Were the instructions easy to understand & follow?</td>
<td>
<div class="switch-field" name="userFriendlyFeedback">
<input type="radio" id="radio-easy-yes" name="switch-easy" value="yes">
<label for="radio-easy-yes">Yes</label>
<input type="radio" id="radio-easy-no" name="switch-easy" value="no">
<label for="radio-easy-no">No</label>
</div>
</td>
</tr>
</table>
<textarea type="feedbackComments" name="comments" placeholder="Please include any comments here"></textarea>
<br>
<button type="submit" class="btn">Submit Feedback</button>
</form>
</div>
【问题讨论】:
-
你查看过这个question吗?
-
我没有 - 但我无法访问 JSFiddle,因为它被防火墙阻止了......如果可能的话,还试图将解决方案保留为纯 HTML / CSS(但会考虑 jQuery- UI 如果最终结果是值得的,并且我很容易如何实现它......)
标签: javascript html css popup draggable