I have encountered an issue with my script that I need assistance with. I am trying to disable this script for responsive or mobile view, but despite trying various methods, it is not functioning as expected.
<script type="text/javascript">
$(function(){ // document ready
if ($('#sidebar').length) { // ensure existence of "#sticky" element
var el = $('#sidebar');
var stickyTop = $('#sidebar').offset().top; // returns a number
var stickyHeight = $('#sidebar').height();
$(window).scroll(function(){ // scroll event
var limit = $('#img1').offset().top - stickyHeight - 15;
var windowTop = $(window).scrollTop(); // returns a number
if (stickyTop < windowTop){
el.css({ position: 'fixed', top: 0 });
}
else {
el.css('position','static');
}
if (limit < windowTop) {
var diff = limit - windowTop;
el.css({top: diff});
}
});
}
});
</script>