-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.mk_localnavi.js
135 lines (95 loc) · 3.18 KB
/
jquery.mk_localnavi.js
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
;/* localnavi
****************************************************************************
/////////////////////////////////////////////////////////////////////////
@varsion : 1.0.2
@require : jquery.js, jquery.effects.core.js jquery.mk_imgHoverSwap.js, jquery.mk_soothScroll.js
@author : http://www.makinokobo.com - oosugi
@last update : 2011.04.14 - oosugi
/////////////////////////////////////////////////////////////////////////
****************************************************************************/
(function($){
$(function(){
var t = $('#headerLogo').css('top').replace('px','') * 1;
var hash = window.location.hash;
// ローカルナビのスムーススクロール設定(ロゴの位置までずらす)
$('#localnavi').mk_smoothScroll({
speed: 1000, // スピードを入力
shift: -t,
easing: 'easeInOutQuart'
});
// ハッシュ付きURLで飛んできた場合
if(hash){
var id = hash.replace('#','');
var target = $('div#'+hash).offset().top;
scrollTo(0,target-t);
}
var $lnavi = $('#localnavi');
var $lnavi_li = $lnavi.find('li');
var $lnavi_img = $lnavi.find('img');
var $sec = $('div.section:regex(id,sec-.*?)');
if($sec.size()){
var secY_array = [];
$sec.each(function(){
var thisY = Math.floor($(this).offset().top);
var thisId = $(this).attr('id');
secY_array.push({id:thisId, y:thisY});
});
// crrent image pre load
$lnavi_img.each(function(){
var src = $(this).attr('src');
var srcCr = src.replace(/_on\.|_out\./,'_cr.');
$('<img/>',{
'src': srcCr
});
});
var thisID;
var prevID;
// window scroll event
$(window).bind('scroll.mk_lnavActive', function(e){
var pageY = $(window).scrollTop();
$.each(secY_array, function(i,val){
if( (pageY - val.y) >= -t ){
thisID = val.id;
}
});
if( pageY < secY_array[0].y -t ){
thisID = '';
}
if(prevID != thisID){
prevID = thisID;
$lnavi_img.each(function(){
var $img = $(this);
var src = $img.attr('src');
if( src.indexOf('_cr.') || src.indexOf('_on.') ){
var outSrc = src.replace(/_cr\.|_on\./,'_out.');
$img.attr('src',outSrc);
}
});
$lnavi_img.mk_imgHoverSwap();
var $active = $lnavi_li.find('a:[href$=#'+thisID+']');
if($active.size()){
var $active_img = $active.find('img');
var actImgSrc = $active_img.attr('src');
var actImgSrcCr = actImgSrc.replace(/_out\./,'_cr.');
$active_img.attr('src',actImgSrcCr);
$active_img.unbind('mouseleave').unbind('mouseenter');
$active_img
.mouseenter(function(){
var src = $(this).attr('src');
$(this).attr('src',src.replace(/_cr\./,'_on.'));
})
.mouseleave(function(){
var src = $(this).attr('src');
$(this).attr('src',src.replace(/_on\./,'_cr.'));
});
/*
if(navigator.userAgent.indexOf("MSIE 6") != -1){
DD_belatedPNG.fix(DD_belatedPNG_target);
}
*/
}
}
});
}
});
})(jQuery);