Authored by 徐炜

逛详情优化

... ... @@ -41,12 +41,22 @@ const _pageArticleContent = (articleContent, isApp, gender) => {
joinContentFunc(++i, len);
} else if (art.singleImage && art.singleImage.data && art.singleImage.data.length) { // 单张图
build.bigImage = helpers.image(art.singleImage.data[0].src, 640, 640);
// 前三张图片不使用懒加载,下同
if (i <= 3) {
build.noLazy = true;
}
contents.push(build);
joinContentFunc(++i, len);
} else if (art.smallPic && art.smallPic.data && art.smallPic.data.length > 1) {
let imgs = art.smallPic.data;
if (i <= 3) {
build.noLazy = true;
}
build.smallImage = [{
src: helpers.image(imgs[0].src, 315, 420)
}, {
... ...
... ... @@ -5,7 +5,7 @@
{{# author}}
<div class="author" data-id={{id}}>
<a class="clearfix" href={{url}}>
<img class="avatar" src={{avatar}}>
<img class="avatar" src={{image2 avatar mode=2 q=60}}>
<span class="name">{{name}}</span>
<span class="intro">{{intro}}</span>
</a>
... ... @@ -27,15 +27,25 @@
{{#if bigImage}}
<div class="post-block big-img-block">
<img class="lazy" data-original={{bigImage}}>
{{#if noLazy}}
<img src={{image2 bigImage q=60}}>
{{else}}
<img class="lazy" data-original={{image2 bigImage q=60}}>
{{/if}}
</div>
{{/if}}
{{#if smallImage}}
<div class="post-block small-img-block clearfix">
{{#if noLazy}}
{{# smallImage}}
<img src={{image2 src q=60}}>
{{/ smallImage}}
{{else}}
{{# smallImage}}
<img class="lazy" data-original={{src}}>
<img class="lazy" data-original={{image2 src q=60}}>
{{/ smallImage}}
{{/if}}
</div>
{{/if}}
... ... @@ -156,7 +166,7 @@
<img class="lazy {{#if squareThumb}}square{{/if}}" data-original={{thumb}}>
<span class="title">{{title}}</span>
<span class="publish-time">
<i class="iconfont">&#xe603;</i>
<i class="iconfont">&#xe603;</i>
{{publishTime}}
</span>
</a>
... ...
... ... @@ -4,7 +4,7 @@
* @date: 2015/10/21
*/
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer');
Hammer = require('./common/toy-hammer');
var $footer = $('#yoho-footer'),
$yohoPage = $('.yoho-page'),
... ...
// 超轻量锤子,业务代码不用动,替换掉重量级的 hammer.js
const $ = require('yoho-jquery');
const ToyHammer = function(elem) {
this.elem = elem;
};
const EVENT_MAPPER = {
tap: 'touchstart'
};
ToyHammer.prototype.on = function(event, fn) {
const mappedEvent = EVENT_MAPPER[event];
if (this.elem && mappedEvent) {
$(this.elem).on(mappedEvent, function(e) {
fn({
srcEvent: e
});
});
}
};
module.exports = ToyHammer;
... ...
... ... @@ -5,7 +5,7 @@
*/
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer'),
Hammer = require('../common/toy-hammer'),
ellipsis = require('yoho-mlellipsis'),
lazyLoad = require('yoho-jquery-lazyload'),
Swiper = require('yoho-swiper');
... ...
... ... @@ -7,8 +7,8 @@ require("guang/info-index.page.css")
var $ = require('yoho-jquery'),
ellipsis = require('yoho-mlellipsis'),
lazyLoad = require('yoho-jquery-lazyload'),
IScroll = require('yoho-iscroll/build/iscroll-probe');
lazyLoad = require('yoho-jquery-lazyload');
//IScroll = require('yoho-iscroll/build/iscroll-probe');
var $authorIntro = $('.author .intro');
... ... @@ -31,6 +31,10 @@ require('../common');
require('../plugin/wx-share')();
require('./detail-dynamic');
$('#wrapper').css({
'overflow-y': 'scroll'
});
/**
* 计算搭配的箭头的位置
* @param $curPos 当前focus的搭配项
... ... @@ -112,16 +116,15 @@ function initIscroll() {
if ($yohoHeader.length > 0) {
hH = $yohoHeader.outerHeight();
}
myScroll = new IScroll('#wrapper', {
probeType: 3,
mouseWheel: true,
click: true
});
document.addEventListener('touchmove', function(e) {
e.preventDefault();
}, false);
/*
myScroll = new IScroll('#wrapper', {
probeType: 3,
mouseWheel: true,
click: true
});
document.addEventListener('touchmove', function(e) {
e.preventDefault();
}, false);
if (!hasCollocationBlock) {
myScroll.on('scroll', function() {
... ... @@ -130,6 +133,9 @@ function initIscroll() {
return;
}
*/
winH = $(window).height() - hH;
fixedThumbDom = $fixedThumbContainer[0];
... ... @@ -137,56 +143,59 @@ function initIscroll() {
cbH = $coBlock.outerHeight();
cbTop = $coBlock.offset().top - hH;
myScroll.on('scroll', function() {
$(window).on('scroll', function() {
console.log(1);
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');
.addClass('fixed-bottom')
.removeClass('hide');
}
} else if (sTop <= cbTop) {
if (classList.indexOf('hide') === -1) {
$fixedThumbContainer
.addClass('hide')
.removeClass('fixed-bottom fixed-top');
.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', '');
.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');
.addClass('absolute')
.removeClass('fixed-top hide');
}
fixedThumbDom.style.top = cbTop + hH + cbH - tcH - sTop + 'px';
} else if (sTop > cbTop + cbH) {
if (classList.indexOf('hide') === -1) {
$fixedThumbContainer
.addClass('hide')
.removeClass('absolute');
.addClass('hide')
.removeClass('absolute');
}
}
$scroller.trigger('scroll');
//$scroller.trigger('scroll');
});
}
// window onload 后重新refresh iscroll
window.onload = function() {
myScroll && myScroll.refresh();
};
/*
// window onload 后重新refresh iscroll
window.onload = function() {
myScroll && myScroll.refresh();
};
// 图片加载完成之后重新 refresh iscroll
$('img').on('load', function() {
myScroll && myScroll.refresh();
});
// 图片加载完成之后重新 refresh iscroll
$('img').on('load', function() {
myScroll && myScroll.refresh();
});
*/
// 初始化页面,包括是否使用iscorll初始化页面
// 接口暴露在HTML中,使用压缩名
... ... @@ -231,17 +240,19 @@ $('img').on('load', function() {
// offset.left约等于marginLeft的值则表示介绍被换行,则清除intro的paddingTop让其更靠近头像和作者名
if ($authorIntro.offset() && (parseInt($authorIntro.offset().left, 10) ===
parseInt($authorIntro.css('margin-left'), 10))) {
parseInt($authorIntro.css('margin-left'), 10))) {
$authorIntro.css('padding-top', 0);
}
/*
if (pageInIscroll) {
if ($('.yoho-header').length > 0) {
$('#wrapper').addClass('ios has-head');
} else {
$('#wrapper').addClass('ios');
}
}
if (pageInIscroll) {
if ($('.yoho-header').length > 0) {
$('#wrapper').addClass('ios has-head');
} else {
$('#wrapper').addClass('ios');
}
}
*/
// 有搭配模块,iphone使用iscroll初始化滚动并有固定的搭配栏,其他的没有
if (hasCollocationBlock) {
... ... @@ -270,7 +281,6 @@ $('img').on('load', function() {
if (pageInIscroll) {
$fixedThumbContainer.delegate('.thumb', 'touchend', thumbTouchEvt);
}
}
... ... @@ -278,3 +288,4 @@ $('img').on('load', function() {
initIscroll();
}
}());
... ...
... ... @@ -5,7 +5,7 @@
*/
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer'),
Hammer = require('../common/toy-hammer'),
ellipsis = require('yoho-mlellipsis'),
lazyLoad = require('yoho-jquery-lazyload'),
Swiper = require('yoho-swiper');
... ...
... ... @@ -5,7 +5,7 @@
*/
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer'),
Hammer = require('../common/toy-hammer'),
ellipsis = require('yoho-mlellipsis'),
lazyLoad = require('yoho-jquery-lazyload');
... ...