on
Italy
- Get link
- X
- Other Apps
width="100%" height="100%" cellspacing="0" cellpadding="0">
colspan="2">Header
.sticky{ transform: translateY(0px);-webkit-transform: translateY(0px);-moz-transform: translateY(0px);-webkit-transition: all 0.8s;-moz-transition: all 0.8s;transition: all 0.8s;}
Javascript:var isMoz = $.browser.mozilla;
var mozMatrix = /matrix\(\s*-?\d+(?:\.\d+)?\s*,\s*-?\d+(?:\.\d+)?\s*,\s*-?\d+(?:\.\d+)?\s*,\s*-?\d+(?:\.\d+)?\s*\,\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s*\)/;
function getMozTransformProp(prop) {
var mMatrix = { y: 0 };
var match = transformString.match(mozMatrix);
if (match) { mMatrix.y = match[2]; }
return mMatrix;
}
var flot = $('.sticky'); //Sticky element Classname or Id
var _top = flot.offset().top;
var getMatrix = null;
getMatrix = window.getComputedStyle(flot.get(0));
var matrix;
if (!isMoz) {
matrix = window.WebKitCSSMatrix ? new WebKitCSSMatrix(getMatrix.webkitTransform).m42 : new MSCSSMatrix(getMatrix.transform).m42;
} else {
//Mozilla hack
var transForm = getMatrix.MozTransform;
var t = getMozTransformProp(transForm);
matrix = t.f;
}
var sticky= function () {
var w = $(document).scrollTop(), winht = screen.availHeight, ftPos = $('footer').offset().top, fHt = flot.innerHeight(true);
offset = (matrix + $(document).scrollTop()) - _top;
if (w < (ftPos-fHt) && w > _top) {
$(flot).css({ '-webkit-transform': 'translateY(' + offset + 'px)', '-moz-transform': 'translateY(' + offset + 'px)', 'transform': 'translateY(' + offset + 'px)' });
}
if (w < _top) {
$(flot).css({ '-webkit-transform': 'translateY(0px)', '-moz-transform': 'translateY(0px)', 'transform': 'translateY(0px)' });
}
}
window.addEventListener('scroll', function () {sticky();}, false);
sticky();
DEMO
Comments
Post a Comment