index.page.js
1.14 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
/**
* 品牌页
* @author: zxr<xiaoru.zhang@yoho.cn>
* @date: 2016/07/09
*/
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload');
var $list = $('.brands-list'),
$gory = $('.brands-category'),
$category = $gory.find('a'),
categoryHeight = $category.height(),
categoryTop = $category.offset() ? $category.offset().top : 0;
require('../common/header');
require('../common/return-top');
lazyLoad($('.brand-page img.lazy'));
// 品牌类别滚动事件
$(window).scroll(function() {
if ($(this).scrollTop() >= categoryTop) {
$gory.addClass('category-fix');
} else {
$gory.removeClass('category-fix');
}
});
// 点击字母,页面滚动到相关区域
$category.click(function() {
var name = $(this).attr('href').split('#')[1],
targetTop = $list.find('[name=' + name + ']').offset().top - categoryHeight;
$('.category-nav').find('a').css('color', '#222');
$(this).css('color', '#379ed6');
if (!$gory.hasClass('category-fix')) {
targetTop -= categoryHeight;
}
$('html,body').animate({
scrollTop: targetTop
}, 200);
return false;
});