...
|
...
|
@@ -20,6 +20,26 @@ exports.init = function() { |
|
|
containerH,
|
|
|
containerTop;
|
|
|
|
|
|
/**
|
|
|
* 计算小箭头位置函数
|
|
|
* @param index(类型为number,调用函数li的index)
|
|
|
*/
|
|
|
arrowPosition = function (element,index) {
|
|
|
var clientWidth = document.documentElement.clientWidth,
|
|
|
container = element,
|
|
|
item = container.find('li'),
|
|
|
len = item.size(),
|
|
|
midNum = Math.ceil(len / 2),
|
|
|
documentFont = parseInt($("html").css("fontSize")),
|
|
|
itemMarginRight = parseInt(item.css('marginRight'))/ documentFont * 40,
|
|
|
itemWidth = item.width() / documentFont * 40,
|
|
|
surPlusValue = parseInt(container.css('padding-left'))/ documentFont * 40 - itemMarginRight,
|
|
|
backgroundLeft;
|
|
|
|
|
|
backgroundLeft = -(320 - (index - midNum) * (itemWidth + itemMarginRight) - surPlusValue)/40 + 'rem';
|
|
|
container.css({"backgroundPosition":backgroundLeft + " bottom"})
|
|
|
};
|
|
|
|
|
|
//点击分类,显示分类下推荐商品列表
|
|
|
thumbContainer.delegate('.thumb', 'click', function() {
|
|
|
var curItem,
|
...
|
...
|
@@ -29,6 +49,7 @@ exports.init = function() { |
|
|
index = curItem.index();
|
|
|
thumbContainer.find('.thumb').removeClass('focus')
|
|
|
curItem.addClass('focus');
|
|
|
arrowPosition(thumbContainer,index + 1);
|
|
|
|
|
|
prodList.find('.prod')
|
|
|
.addClass('hide')
|
...
|
...
|
@@ -66,15 +87,23 @@ exports.init = function() { |
|
|
thumbContainer
|
|
|
.addClass('fixed-bottom')
|
|
|
.removeClass('static');
|
|
|
prodList.css({
|
|
|
'margin-top': tContainerH
|
|
|
});
|
|
|
} else if (sTop <= containerTop) {
|
|
|
thumbContainer
|
|
|
.addClass('static')
|
|
|
.removeClass('fixed-bottom fixed-top');
|
|
|
.removeClass('fixed-bottom fixed-top')
|
|
|
.css('top' , '');
|
|
|
prodList.removeAttr('style')
|
|
|
} else if (sTop <= containerTop + containerH - tContainerH) {
|
|
|
thumbContainer
|
|
|
.addClass('fixed-top')
|
|
|
.removeClass('static absolute')
|
|
|
.removeAttr('style');
|
|
|
.css('top' , '');
|
|
|
prodList.css({
|
|
|
'margin-top': tContainerH
|
|
|
});
|
|
|
} else if (sTop <= containerTop + containerH) {
|
|
|
thumbContainer
|
|
|
.addClass('absolute')
|
...
|
...
|
@@ -82,11 +111,15 @@ exports.init = function() { |
|
|
.css({
|
|
|
top: containerTop + containerH - tContainerH
|
|
|
});
|
|
|
prodList.css({
|
|
|
'margin-top': tContainerH
|
|
|
});
|
|
|
} else if (sTop > containerTop + containerH) {
|
|
|
thumbContainer
|
|
|
.addClass('static')
|
|
|
.removeClass('absolute')
|
|
|
.removeAttr('style');
|
|
|
.css('top' , '');
|
|
|
prodList.removeAttr('style');
|
|
|
}
|
|
|
});
|
|
|
|
...
|
...
|
@@ -95,23 +128,5 @@ exports.init = function() { |
|
|
$(document).scroll();
|
|
|
}
|
|
|
|
|
|
//计算小箭头位置
|
|
|
(function (doc, win) {
|
|
|
var docEl = doc.documentElement,
|
|
|
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
|
|
|
arrowPosition = function () {
|
|
|
var clientWidth = docEl.clientWidth;
|
|
|
if (!clientWidth) {
|
|
|
return;
|
|
|
}
|
|
|
docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
|
|
|
};
|
|
|
|
|
|
if (!doc.addEventListener) {
|
|
|
return;
|
|
|
}
|
|
|
win.addEventListener(resizeEvt, arrowPosition, false);
|
|
|
doc.addEventListener('DOMContentLoaded', arrowPosition, false);
|
|
|
})(document, window);
|
|
|
});
|
|
|
}; |
|
|
\ No newline at end of file |
...
|
...
|
|