saunter.js
2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* '逛'js
* @author: yue.liu@yoho.cn
* @date;2015/3/31
*/
var $ = require('jquery'),
ellipsis = require('mlellipsis');
require('lazyload');
require('./saunter/article-type-three');
/**
* 初始化页面加载时的文字截取和图片懒加载功能
*/
exports.init = function() {
$(function() {
var $loginTip = $('#login-tip'),
winH,
winW,
tipH,
tipW;
//头部作者信息样式计算(在描述信息过长时换行显示, 去除intro的padding-top)
var $linkC = $('#link-container'),
$avatar = $linkC.find('.avatar'),
$name = $linkC.find('.name'),
$intro = $linkC.find('.intro');
if ($avatar.outerWidth(true) + $name.outerWidth(true) + $intro.outerWidth(true) > $(window).width()) {
$intro.css('padding-top', 0);
}
//相关文章截取文字
ellipsis.init();
$('.post-list').find('span').each(function() {
$(this).mlellipsis(2);
});
//图片懒加载
$('img.lazy').lazyload();
$('.thumb-container img.lazy').lazyload({
event: 'load'
});
//提示信息位置
winH = $(window).height();
winW = $(window).width();
tipH = $loginTip.height();
tipW = $loginTip.width();
$loginTip.css({
top: (winH - tipH) / 2,
left: (winW - tipW) / 2
});
//绑定商品信息的收藏和取消收藏事件(相关推荐和搭配模块)
$('.good-list, .prod-list').delegate('.good-islike', 'touchstart', function(e) {
var $cur = $(e.currentTarget),
$good = $cur.closest('.good-info'),
id = $good.data('id');
$.ajax({
type: 'GET',
url: '/favorite/product',
data: {
st: 1,
product_skn: id
}
}).then(function(data) {
if (data.code === 200) {
$cur.toggleClass('good-like');
} else if (data.code === 400) {
//提示登录信息
$('#login-tip').fadeIn(500, function() {
setTimeout(function() {
$('#login-tip').fadeOut(500);
}, 1000);
});
}
});
});
});
};