init.js
2.79 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
85
86
87
88
89
$(function() {
// 截取参数方法
$.getUrlParam = function(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)")
var r = window.location.search.substr(1).match(reg)
if (r != null) {
return unescape(r[2])
} else {
return null
}
}
window.load = function(contentId, $default) {
var $el = $('#' + contentId)
// $footer = $('#footer')
$el.load('./' + $default + '.html')
$('.menu-name').click(function() {
var $this = $(this)
var url = './' + $this.attr('data-url') + '.html'
// $footer.hide()
$el.hide().load(url, function() {
$el.fadeIn()
// $footer.show()
})
$('.menu-item a').removeClass('menu-active')
$this.addClass('menu-active')
})
}
$('head').append('<link rel="shortcut icon" href="../../images/common/favicon.ico" /><link rel="preload" as="style" href="../../css/common.css"><link rel="stylesheet" href="../../css/common.css">')
var $body = $('body')
$body.hide()
var $footer = $("<footer id='footer'></footer>")
$footer.load('/html/components/footer.html')
var $header = $("<header id='header' class='clearfix'></header>"),
__data = null
$header.load('/html/components/header.html', function() {
$body.fadeIn(10)
__data = $.getUrlParam('data')
__data != null && $('.menu-name').eq(__data).trigger('click')
}).appendTo($body.append($footer))
// $(window).scroll(function (e) {
// if ($(document).scrollTop() >= 430) {
// $('.menu-box').addClass('fixed')
// } else if ($(document).scrollTop() < 430) {
// $('.menu-box').removeClass('fixed')
// }
// })
// 防抖
function debounce(fn, wait) {
var timeout = null;
return function() {
if (timeout !== null)
clearTimeout(timeout);
timeout = setTimeout(fn, wait);
}
}
var $document = $(document),
$menu_box = $('.menu-box'),
scrollTop = 0
// 滚动事件
$menu_box && window.addEventListener('scroll', debounce(function() {
scrollTop = $document.scrollTop()
if (scrollTop >= 430) {
!$menu_box.hasClass('fixed') && $menu_box.addClass('fixed')
} else {
$menu_box.hasClass('fixed') && $menu_box.removeClass('fixed')
}
}, 1));
(function() {
if (/s=noRedirect/i.test(location.search)) return;
if (
/AppleWebKit.*Mobile/i.test(navigator.userAgent) ||
/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(
navigator.userAgent
)
) {
try {
if (
/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(
navigator.userAgent
)
) {
window.location.href = '../../dist/index.html';
}
} catch (e) {}
}
})();
})