/** Copyright 2014 Colm Delaney * Released under the MIT License: * http://www.opensource.org/licenses/mit-license.php * * To use this file, remove .txt extension, and place it within the appropriate project directory */ // Detect whether scrollbars are present and if document is scrolled and add/remove appropriate classes // Run on document.ready, window.resize and (optionally) on window.scroll // usage: $('html').add_scroll_classes(); (function($) { $.fn.add_scroll_classes = function() { // (re)initialise to "no scrollbars" state $(this).removeClass('no-scroll no-vertical-scroll no-horizontal-scroll scroll vertical-scroll horizontal-scroll not-scrolled not-scrolled-vertically not-scrolled-horizontally scrolled scrolled-vertically scrolled-horizontally').addClass('no-scroll no-vertical-scroll no-horizontal-scroll not-scrolled not-scrolled-vertically not-scrolled-horizontally'); if ($(document).height() > $(window).height()) { $(this).removeClass('no-scroll no-vertical-scroll').addClass('scroll vertical-scroll'); if ($(document).scrollTop() > 0) { $(this).removeClass('scrolled not-scrolled not-scrolled-vertically').addClass('scrolled scrolled-vertically'); } } if ($(document).width() > $(window).width()) { $(this).removeClass('no-scroll no-horizontal-scroll').addClass('scroll horizontal-scroll'); if ($(document).scrollLeft() > 0) { $(this).removeClass('scrolled not-scrolled not-scrolled-horizontally').addClass('scrolled scrolled-horizontally'); } } }; })(jQuery);