Created
September 10, 2015 14:26
-
-
Save asacolips/e4184fd5041de4b07b26 to your computer and use it in GitHub Desktop.
Detect first item in line wrap | jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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