teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

詳細なコードの記載

2015/06/16 07:25

投稿

141kanae
141kanae

スコア28

title CHANGED
File without changes
body CHANGED
@@ -18,4 +18,60 @@
18
18
  必要な記述がないわけではないかと思います。
19
19
 
20
20
  ブラウザ依存の問題なのでしょうか。
21
- 考えられる原因があれば、小さなことでも構いませんのでご協力頂ければ助かります。
21
+ 考えられる原因があれば、小さなことでも構いませんのでご協力頂ければ助かります。
22
+
23
+ ###HTML
24
+ <ul id="home" class="gnavi">
25
+ <li><a href="/"><img src="○○○.gif" alt="○○○" width="115" height="46" id="home" /></a></li>
26
+ <li><a href="/"><img src="○○○.gif" alt="○○○" width="157" height="46" class="btn" /></a></li>
27
+ <li><a href="/"><img src="○○○.gif" alt="○○○" width="157" height="46" class="btn" /></a></li>
28
+ <li><a href="/"><img src="○○○.gif" alt="○○○" width="157" height="46" class="btn" /></a></li>
29
+ <li><a href="/"><img src="○○○.gif" alt="○○○" width="157" height="46" class="btn" /></a></li>
30
+ <li><a href="/"><img src="○○○.gif" alt="○○○" width="157" height="46" class="btn" /></a></li>
31
+
32
+ ###JS(http://www.kyosuke.jp/yugajs/)
33
+ <script type="text/javascript" src="/design/btoner/js/yuga.js" charset="utf-8"></script>
34
+
35
+ //ロールオーバー
36
+ rollover: function(options) {
37
+ var c = $.extend({
38
+ hoverSelector: '.btn, .allbtn img',
39
+ groupSelector: '.btngroup',
40
+ postfix: '_on'
41
+ }, options);
42
+ //ロールオーバーするノードの初期化
43
+ var rolloverImgs = $(c.hoverSelector).filter(isNotCurrent);
44
+ rolloverImgs.each(function(){
45
+ this.originalSrc = $(this).attr('src');
46
+ this.rolloverSrc = this.originalSrc.replace(new RegExp('('+c.postfix+')?(\.gif|\.jpg|\.png)$'), c.postfix+"$2");
47
+ this.rolloverImg = new Image;
48
+ this.rolloverImg.src = this.rolloverSrc;
49
+ });
50
+ //グループ内のimg要素を指定するセレクタ生成
51
+ var groupingImgs = $(c.groupSelector).find('img').filter(isRolloverImg);
52
+
53
+ //通常ロールオーバー
54
+ rolloverImgs.not(groupingImgs).hover(function(){
55
+ $(this).attr('src',this.rolloverSrc);
56
+ },function(){
57
+ $(this).attr('src',this.originalSrc);
58
+ });
59
+ //グループ化されたロールオーバー
60
+ $(c.groupSelector).hover(function(){
61
+ $(this).find('img').filter(isRolloverImg).each(function(){
62
+ $(this).attr('src',this.rolloverSrc);
63
+ });
64
+ },function(){
65
+ $(this).find('img').filter(isRolloverImg).each(function(){
66
+ $(this).attr('src',this.originalSrc);
67
+ });
68
+ });
69
+ //フィルタ用function
70
+ function isNotCurrent(i){
71
+ return Boolean(!this.currentSrc);
72
+ }
73
+ function isRolloverImg(i){
74
+ return Boolean(this.rolloverSrc);
75
+ }
76
+
77
+ },