Skip to content

Instantly share code, notes, and snippets.

@asacolips
Created September 10, 2015 14:26
Show Gist options
  • Save asacolips/e4184fd5041de4b07b26 to your computer and use it in GitHub Desktop.
Save asacolips/e4184fd5041de4b07b26 to your computer and use it in GitHub Desktop.
Detect first item in line wrap | jQuery
'use strict';
$(document).ready(function() {
// Function to add class to first item in line wrap
function firstWrapClass(selector, classToApply) {
var offset = 0;
var last = 0;
selector.each(function () {
$(this).removeClass(classToApply);
offset = $(this).offset().left;
if (offset < last) {
$(this).addClass(classToApply);
}
last = offset;
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment