質問編集履歴

3

タグを追加しました。

2015/12/09 06:22

投稿

k_fujimoto
k_fujimoto

スコア181

test CHANGED
File without changes
test CHANGED
File without changes

2

htmlの記述を追加しました。

2015/12/09 06:22

投稿

k_fujimoto
k_fujimoto

スコア181

test CHANGED
@@ -1 +1 @@
1
- JavaScript】一部の環境でoffsetの値がうまく取得できません。
1
+ JavaScriptでoffsetの値が取得できません。
test CHANGED
@@ -8,11 +8,73 @@
8
8
 
9
9
  ###行ったこと
10
10
 
11
+ ```html
12
+
13
+ <html>
14
+
15
+ <head>
16
+
17
+ </head>
18
+
19
+ <body>
20
+
21
+ <section class="block">
22
+
23
+ <div class="block__element">
24
+
25
+ <div class="block__elementArea">
26
+
27
+ <p>ここにコンテンツが入ります。</p>
28
+
29
+ <p>ここにコンテンツが入ります。</p>
30
+
31
+ <p>ここにコンテンツが入ります。</p>
32
+
33
+ <p>ここにコンテンツが入ります。</p>
34
+
35
+ <p>ここにコンテンツが入ります。</p>
36
+
37
+ </div>
38
+
39
+ </div>
40
+
41
+ </section>
42
+
43
+ <section class="block">
44
+
45
+ <div class="block__elementArea">
46
+
47
+ <div class="">
48
+
49
+ <p>ここにコンテンツが入ります。</p>
50
+
51
+ <p>ここにコンテンツが入ります。</p>
52
+
53
+ <p>ここにコンテンツが入ります。</p>
54
+
55
+ <p>ここにコンテンツが入ります。</p>
56
+
57
+ <p>ここにコンテンツが入ります。</p>
58
+
59
+ </div>
60
+
61
+ </div>
62
+
63
+ </section>
64
+
65
+ </body>
66
+
67
+ </html>
68
+
69
+ ```
70
+
71
+
72
+
11
73
  ```Javascript
12
74
 
13
75
  $(function(){
14
76
 
15
- $('.content > .content__element').each(function(){
77
+ $('.block > .block__element').each(function(){
16
78
 
17
79
  var $target = $(this);
18
80
 
@@ -20,7 +82,7 @@
20
82
 
21
83
  if ($h > 100) {
22
84
 
23
- $target.addClass('is-hidden content__elementArea');
85
+ $target.addClass('hidden block__elementArea');
24
86
 
25
87
  $target.append(
26
88
 
@@ -30,11 +92,11 @@
30
92
 
31
93
  $target.find('.j-areaToggle').on('click', function(){
32
94
 
33
- var $position = $target.offset().top - 40;
95
+ var $position = $target.offset().top - 80;
34
96
 
35
97
  var $scrollTag = ( window.chrome || 'WebkitAppearance' in document.documentElement.style )? 'body' : 'html';
36
98
 
37
- $target.toggleClass('is-hidden');
99
+ $target.toggleClass('hidden');
38
100
 
39
101
  $target.find('.clickArea').toggleClass('clickArea--before');
40
102
 
@@ -60,7 +122,7 @@
60
122
 
61
123
  ###問題
62
124
 
63
- 一部の環境で.content_elementの値がうまく取得できない。
125
+ 一部の環境で.block__elementのoffsetの値がうまく取得できない。
64
126
 
65
127
 
66
128
 

1

環境の説明を追加

2015/12/09 05:05

投稿

k_fujimoto
k_fujimoto

スコア181

test CHANGED
File without changes
test CHANGED
@@ -76,6 +76,10 @@
76
76
 
77
77
 
78
78
 
79
+ ※ブラウザがsafariの場合、デバイスがPCの場合は、正常に`$position`を取得できております。
80
+
81
+
82
+
79
83
  ---
80
84
 
81
85
  初めての質問で至らない点があると思いますが、ご教授お願い致します。