Does anybody know how I can make this modal popup form, movable / draggable?
Ideally, I would like it to initially "appear" at the top-right or bottom-right of the screen - a slide-in animation would be great too - but for the user to then have the ability to move/drag it to another location (as depending on the screen size / resolution etc., it may be covering something on the parent page) I suspect there's something in the existing CSS that's "locking" it in place.
(Bonus points if anybody knows how I can make the popup initially "slide" in rather than simply appear - currently using a simple display:none / display:block switch inside a function - but this is not essential...)
Thanks!
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>