Authored by xuqi

guang detail

... ... @@ -6,7 +6,97 @@
var $ = require('yoho.zepto'),
ellipsis = require('mlellipsis'),
lazyLoad = require('yoho.lazyload');
lazyLoad = require('yoho.lazyload'),
IScroll = require('iscroll/iscroll-probe');
var $authorIntro = $('.author .intro');
var isIphone = navigator.userAgent.indexOf('iPhone') > 0 ? true : false;
var hasCollocationBlock = $('.collocation-block').length > 0 ? true : false;
//collocation block variable
var thumbWidth = 0,
$fixedThumbContainer = $(''),
$coBlock, $thumbContainer, $thumbs, $prods,
scrollToEl;
var scrollToEl = document.querySelector('#wrapper .collocation-block');
var winW = $(window).width();
var myScroll;
/**
* 计算搭配的箭头的位置
* @param $curPos 当前focus的搭配项
*/
function posCollocationArrow($curCo) {
var left = $curCo.offset().left,
bgPos = -winW + left + (thumbWidth / 2) + 'px';
$thumbContainer.css({
backgroundPosition: bgPos + ' bottom'
});
if (isIphone) {
$fixedThumbContainer.css({
backgroundPosition: bgPos + ' bottom'
});
}
}
//搭配thumb的touch事件句柄
function thumbTouchEvt(e) {
var $curCo = $(e.currentTarget),
index = $curCo.index(),
$brother, $brotherCo,
$curProds;
if ($curCo.hasClass('focus')) {
return;
}
$thumbs.filter('.focus').removeClass('focus');
if (isIphone) {
if ($curCo.closest('.fixed-thumb-container').length > 0) {
$brother = $thumbContainer;
} else {
$brother = $fixedThumbContainer;
}
$brotherCo = $brother.find('.thumb').eq(index);
$fixedThumbContainer.find('.thumb.focus').removeClass('focus');
$brotherCo.addClass('focus');
}
$curCo.addClass('focus');
//定位arrow
posCollocationArrow($curCo);
$prods.not('.hide').addClass('hide');
$curProds = $prods.eq(index);
$curProds.removeClass('hide');
//
lazyLoad($curProds.find('.lazy'));
if (isIphone) {
if (myScroll) {
myScroll.scrollToElement(scrollToEl, 400);
}
} else {
$('body').animate({
scrollTop: $coBlock.offset().top
}, 400);
}
}
if (isIphone) {
$('#wrapper').addClass('ios');
}
ellipsis.init();
... ... @@ -15,4 +105,114 @@ lazyLoad($('.lazy'));
//title mlellipsis
$('.info-list .title, .one-good .reco-name').each(function() {
this.mlellipsis(2);
});
\ No newline at end of file
});
//offset.left约等于marginLeft的值则表示介绍被换行,则清除intro的paddingTop让其更靠近头像和作者名
if (parseInt($authorIntro.offset().left, 10) === parseInt($authorIntro.css('margin-left'), 10)) {
$authorIntro.css('padding-top', 0);
}
//有搭配模块,iphone使用iscroll初始化滚动并有固定的搭配栏,其他的没有
if (hasCollocationBlock) {
$coBlock = $('.collocation-block');
$thumbContainer = $coBlock.children('.thumb-container');
$thumbs = $thumbContainer.find('li');
$prods = $coBlock.find('.prod');
thumbWidth = $thumbs.width();
if (isIphone) {
$fixedThumbContainer = $('#wrapper')
.after($thumbContainer.clone().addClass('fixed-thumb-container fixed-bottom'))
.next('.thumb-container');
//load img of fixed thumb container
lazyLoad($fixedThumbContainer.find('.lazy'), {
event: 'sporty'
});
}
//Init Arrow Position
posCollocationArrow($thumbs.filter('.focus'));
$thumbContainer.delegate('.thumb', 'touchend', thumbTouchEvt);
if (isIphone) {
$fixedThumbContainer.delegate('.thumb', 'touchend', thumbTouchEvt);
}
}
// 初始化iscroll
window.onload = function() {
var $scroller = $('#scroller');
var winH, tcH, cbH, cbTop, fixedThumbDom;
if (!isIphone) {
return;
}
myScroll = new IScroll('#wrapper', {
probeType: 3,
mouseWheel: true,
click: true
});
document.addEventListener('touchmove', function (e) {
e.preventDefault();
}, false);
if (!hasCollocationBlock) {
myScroll.on('scroll', function() {
$scroller.trigger('scroll');
});
return;
}
winH = $(window).height();
fixedThumbDom = $fixedThumbContainer[0];
tcH = $thumbContainer.height();
cbH = $coBlock.height();
cbTop = $coBlock.offset().top;
myScroll.on('scroll', function() {
var sTop = -this.y;
var classList = fixedThumbDom.className;
if (sTop <= cbTop - winH + tcH) {
if (classList.indexOf('fixed-bottom') === -1) {
$fixedThumbContainer
.addClass('fixed-bottom')
.removeClass('hide');
}
} else if (sTop <= cbTop) {
if (classList.indexOf('hide') === -1) {
$fixedThumbContainer
.addClass('hide')
.removeClass('fixed-bottom fixed-top');
}
} else if (sTop <= cbTop + cbH - tcH) {
if (classList.indexOf('fixed-top') === -1) {
$fixedThumbContainer
.addClass('fixed-top')
.removeClass('hide absolute')
.css('top', '');
}
} else if (sTop <= cbTop + cbH) {
if (classList.indexOf('absolute') === -1) {
$fixedThumbContainer
.addClass('absolute')
.removeClass('fixed-top hide');
}
fixedThumbDom.style.top = cbTop + cbH - tcH - sTop + 'px';
} else if (sTop > cbTop + cbH) {
if (classList.indexOf('hide') === -1) {
$fixedThumbContainer
.addClass('hide')
.removeClass('absolute');
}
}
$scroller.trigger('scroll');
});
};
\ No newline at end of file
... ...
... ... @@ -20,7 +20,8 @@
"yoho.jquery": "1.8.3",
"yoho.lazyload": "1.1.0",
"mlellipsis": "0.0.6",
"yoho.iswiper": "3.0.1"
"yoho.iswiper": "3.0.1",
"iscroll": "5.1.2"
},
"devDependencies": {
"expect.js": "0.3.1"
... ...
... ... @@ -55,16 +55,16 @@ $clothes: sprite-map("guang/clothes/*.png");
float: left;
font-size: 28rem / $pxConvertRem;
color: #000;
padding: 30rem / $pxConvertRem;
margin-left: 30rem / $pxConvertRem 0;
padding: 30rem / $pxConvertRem 0;
margin-left: 30rem / $pxConvertRem;
}
.intro {
float: left;
font-size: 28rem / $pxConvertRem;
color: #b0b0b0;
padding: 30rem / $pxConvertRem;
margin-left: 30rem / $pxConvertRem 0;
padding: 30rem / $pxConvertRem 0;
margin-left: 30rem / $pxConvertRem;
}
}
... ... @@ -116,131 +116,135 @@ $clothes: sprite-map("guang/clothes/*.png");
.collocation-block {
background: #fff;
.thumb-container {
padding-top: 30rem / $pxConvertRem;
padding-left: 30rem / $pxConvertRem;
background: transparent image-url('guang/thumb-container-bg.png') no-repeat;
background-size: 100% 100%;
&.fixed-top {
position: fixed;
left: 0;
right: 0;
top: 0;
}
&.fixed-bottom {
position: fixed;
left: 0;
right: 0;
bottom: 0;
background: rgba(255,255,255,0.9);
}
&.absolute {
position: absolute;
left: 0;
right: 0;
}
.good-list {
padding-left:15rem / $pxConvertRem;
}
}
&.static {
position: static;
}
.thumb-container {
padding-top: 30rem / $pxConvertRem;
padding-left: 30rem / $pxConvertRem;
background: transparent image-url('guang/thumb-container-bg.png') no-repeat;
background-size: 200% 100%;
&.fixed-top {
position: fixed;
left: 0;
right: 0;
top: 0;
}
.thumb {
display: inline-block;
position: relative;
margin-right: 22rem / $pxConvertRem;
padding-bottom: 30rem / $pxConvertRem;
&.fixed-bottom {
position: fixed;
left: 0;
right: 0;
bottom: 0;
background: rgba(255,255,255,0.9);
}
&:last-child {
margin-right: 0;
}
&.absolute {
position: absolute;
left: 0;
right: 0;
}
&.focus .thumb-img {
border-color: #000;
}
&.static {
position: static;
}
.thumb-img {
height: 134rem / $pxConvertRem;
width: 96rem / $pxConvertRem;
border: 1px solid transparent;
&.hide {
display: none;
}
}
.good-list {
padding-left:15rem / $pxConvertRem;
.clothe-type {
position: absolute;
right: 6rem / $pxConvertRem;
bottom: 34rem / $pxConvertRem;
width: 20px;
height: 20px;
@include border-radius(50%);
&.bag {
@include retina-sprite ($clothes, bag, 80/20);
background-color: #fff;
background-size: 100%;
}
.clothe-type {
position: absolute;
right: 6rem / $pxConvertRem;
bottom: 34rem / $pxConvertRem;
width: 20px;
height: 20px;
@include border-radius(50%);
&.bag {
@include retina-sprite ($clothes, bag, 80/20);
background-color: #fff;
background-size: 100%;
}
&.cloth {
@include retina-sprite ($clothes, cloth, 80/20);
background-color: #fff;
background-size: 100%;
}
&.dress {
@include retina-sprite ($clothes, dress, 80/20);
background-color: #fff;
background-size: 100%;
}
&.headset {
@include retina-sprite ($clothes, headset, 80/20);
background-color: #fff;
background-size: 100%;
}
&.lamp {
@include retina-sprite ($clothes, lamp, 80/20);
background-color: #fff;
background-size: 100%;
}
&.pants {
@include retina-sprite ($clothes, pants, 80/20);
background-color: #fff;
background-size: 100%;
}
&.shoe {
@include retina-sprite ($clothes, shoe, 80/20);
background-color: #fff;
background-size: 100%;
}
&.swim-suit {
@include retina-sprite ($clothes, swim-suit, 80/20);
background-color: #fff;
background-size: 100%;
}
&.under {
@include retina-sprite ($clothes, under, 80/20);
background-color: #fff;
background-size: 100%;
}
&.watch {
@include retina-sprite ($clothes, watch, 80/20);
background-color: #fff;
background-size: 100%;
}
&.cloth {
@include retina-sprite ($clothes, cloth, 80/20);
background-color: #fff;
background-size: 100%;
}
&.dress {
@include retina-sprite ($clothes, dress, 80/20);
background-color: #fff;
background-size: 100%;
}
&.headset {
@include retina-sprite ($clothes, headset, 80/20);
background-color: #fff;
background-size: 100%;
}
&.lamp {
@include retina-sprite ($clothes, lamp, 80/20);
background-color: #fff;
background-size: 100%;
}
&.pants {
@include retina-sprite ($clothes, pants, 80/20);
background-color: #fff;
background-size: 100%;
}
&.shoe {
@include retina-sprite ($clothes, shoe, 80/20);
background-color: #fff;
background-size: 100%;
}
&.swim-suit {
@include retina-sprite ($clothes, swim-suit, 80/20);
background-color: #fff;
background-size: 100%;
}
&.under {
@include retina-sprite ($clothes, under, 80/20);
background-color: #fff;
background-size: 100%;
}
&.watch {
@include retina-sprite ($clothes, watch, 80/20);
background-color: #fff;
background-size: 100%;
}
}
.thumb {
display: inline-block;
position: relative;
margin-right: 22rem / $pxConvertRem;
padding-bottom: 30rem / $pxConvertRem;
&:last-child {
margin-right: 0;
}
&.focus .thumb-img {
border-color: #000;
}
}
.thumb-img {
height: 134rem / $pxConvertRem;
width: 96rem / $pxConvertRem;
border: 1px solid transparent;
}
.related-reco-block {
... ...
... ... @@ -137,7 +137,7 @@
<ul class="info-list">
{{# relatedInfo}}
<li>
<a href={{url}}>
<a class="clearfix" href={{url}}>
<img class="lazy {{#if squareThumb}}square{{/if}}" data-original={{thumb}}>
<span class="title">{{title}}</span>
<span class="publish-time">
... ...
... ... @@ -56,6 +56,24 @@ class DetailController extends AbstractAction
'isFew' => true,
'url' => ''
)
),
array(
'thumb' => 'http://7xidk0.com1.z0.glb.clouddn.com/clothe.png',
'type' => 'cloth',
'goods' => array(
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/03/02/07/01ebfb219e22770ffb0c2c3a2cbb2b4bef.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => 'GAWS DIGI 丛林数码印花拼接卫衣',
'price' => 1268,
'salePrice' => 589,
'tags' => array(
array(
'isNew' => true
)
),
'isFew' => true,
'url' => ''
)
)
)
)
... ...