garand / sticky

jQuery Plugin for Sticky Objects
Other
3.3k stars 1.06k forks source link

Made sticky wrapper Id unique on page #283

Open bmalets opened 5 years ago

bmalets commented 5 years ago

There is closed an issue related to bad ID of sticky wrapper element: id="undefined-sticky-wrapper"

Current line from master branch defines wrapper ID:

var wrapperId = stickyId ? stickyId + '-' + defaults.wrapperClassName : defaults.wrapperClassName;

It means if your sticky element has id="dummy", wrapper will have id="dummy-sticky-wrapper". If your sticky element does not have an ID - wrapper will have id="undefined-sticky-wrapper".

There is a problem when we have a few sticky elements on page without id (sidebar and header etc.) it's not good to have two wrappers with that same id "undefined-sticky-wrapper"

How about to change this line with:

var wrapperIdSuffix = stickyId ? stickyId : new Date().valueOf();
var wrapperId = defaults.wrapperClassName + '-' + wrapperIdSuffix;

In this case wrapper id with will be more readable and it will be always unique on page (because timestamp is unique).