1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- "use strict";
- $(function () {
- var windowWidth = $(window).width(); // 页面滚动偏移
- var offset = 0; // pc端
- if (windowWidth > 768) {
- offset = getScrollOffset('.navbar'); // 导航菜单展开折叠
- collapseToggle('[data-collapse-toggle="category"]', 'click', function (result) {
- var bindEl = result.bindEl,
- parent = result.parent,
- height = result.height,
- isCollapse = result.isCollapse;
- var text = isCollapse ? '展开' : '收起';
- var lineHeight = height - 32;
- bindEl.children('.icon').toggleClass('arrowup');
- bindEl.children('span').text(text);
- parent.children('.name').children('em').height(lineHeight);
- }); // 可折叠楼层
- makeFloorList({
- root: '.floor',
- // 根节点元素
- collapse: '.article',
- //可折叠元素
- item: '.section',
- // 子元素
- touch: '.more-btn',
- // 事件绑定元素
- size: 6,
- // 每页最多显示的子元素个数
- col: 3,
- // 每列最多显示的子元素个数
- minHeight: $('.floor').find('.section').height() + 24,
- // 单个子元素的高度
- // 展开时的回调
- open: function open(floor) {
- if (floor.current === floor.step) {
- floor.$floor.find('.more span').text('收起全部');
- floor.$floor.find('.more .icon').addClass('arrowup');
- }
- },
- // 收起时的回调
- close: function close(floor) {
- floor.$floor.find('.more span').text('查看更多');
- floor.$floor.find('.more .icon').removeClass('arrowup');
- }
- });
- } else {
- // 移动端
- offset = getScrollOffset(['.navbar', '.category']);
- stickyResponse('#category', getScrollOffset('.banner'), function (e) {
- if (e.sticky) {
- $('#category-list').addClass('fixed');
- } else {
- $('#category-list').removeClass('fixed');
- }
- });
- } // 生成导航
- makeNavigate('.floor h2', '.navigate');
- makeNavigate('.floor h2', '#category-list'); // 楼层滚动
- bindCategory('.navigate li,.category-list li', '.floor', offset, function (index) {
- activeCategory('.navigate li, .category-list li', index);
- }); // 页面滚动
- $('.navigate').hide();
- pageScrollObserve('.floor', offset, function (el, index) {
- if (index > -1) {
- windowWidth > 768 && $('.navigate').fadeIn();
- activeCategory('.navigate li, .category-list li', index);
- } else {
- windowWidth > 768 && $('.navigate').fadeOut();
- }
- });
- });
|