Skip to content

Commit

Permalink
Fix sticky alert causing visual bug with exercise frame
Browse files Browse the repository at this point in the history
This improves the code created in #1219.

Fixes #1311
  • Loading branch information
khattam2 authored and ihalaij1 committed Jan 26, 2024
1 parent f49fd38 commit 958e0f1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions course/templates/course/course_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,18 @@ <h4 class="modal-title" id="unenroll-modal-title">
{% endcomment %}

<script>
$(function() {
const hash = window.location.hash;
const target = $(hash);
const stickyAlert = $('.sticky-alert');
if (target.length > 0 && stickyAlert.length > 0) {
const alertHeight = stickyAlert[0].offsetHeight;
target.css('padding-top', alertHeight + 'px');
}
});
$(document).ajaxStop(function(e) {
const stickyAlert = $('.sticky-alert');
if (stickyAlert.length > 0) {
const currentOffset = $(document).scrollTop();
const alertHeight = stickyAlert[0].offsetHeight;
if (currentOffset > alertHeight) {
const offset = currentOffset - alertHeight;
window.scrollTo({ top: offset });
}
}
$(this).unbind('ajaxStop');
});
</script>

{% endblock %}
Expand Down

0 comments on commit 958e0f1

Please sign in to comment.