回答編集履歴

2

chousei

2019/05/31 06:27

投稿

yambejp
yambejp

スコア114839

test CHANGED
@@ -71,3 +71,35 @@
71
71
  <span id="anime"></span>
72
72
 
73
73
  ```
74
+
75
+
76
+
77
+ # performance.navigation.typeの利用
78
+
79
+ performance.navigation.typeの振り分けを考えました
80
+
81
+ ```javascript
82
+
83
+ <script>
84
+
85
+ var flg=window.performance.navigation.type;
86
+
87
+ window.addEventListener('pageshow', function(e){
88
+
89
+ list=["first","reload","back"];
90
+
91
+ console.log(list[flg]);
92
+
93
+ flg=2;
94
+
95
+ });
96
+
97
+ </script>
98
+
99
+ <a href="https://www.google.com">google</a>
100
+
101
+ <a href="#">hash</a>
102
+
103
+ <input type="button" value="reload" onclick="location.reload()">
104
+
105
+ ```

1

chousei

2019/05/31 06:27

投稿

yambejp
yambejp

スコア114839

test CHANGED
@@ -7,3 +7,67 @@
7
7
  10秒程度値を保持、pageshowでフラグがあればページバックとみなす
8
8
 
9
9
  など適当なロジックを組むとよいでしょう
10
+
11
+
12
+
13
+ # sample
14
+
15
+ リロードや、5秒以内に返ってきた場合アニメしない
16
+
17
+ ```javascript
18
+
19
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
20
+
21
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
22
+
23
+ <script>
24
+
25
+ $(function(){
26
+
27
+ $('#reload').on('click',function(){
28
+
29
+ location.reload();
30
+
31
+ });
32
+
33
+ $('#google').on('click',function(){
34
+
35
+ location.href="https://www.google.com";
36
+
37
+ });
38
+
39
+ });
40
+
41
+ $(window).on('pageshow',function(){
42
+
43
+ var anime=$.cookie('anime');
44
+
45
+ console.log(anime);
46
+
47
+ if(typeof anime=="undefined"){
48
+
49
+ $('#anime').text('anime...').delay(2000).queue(function(){
50
+
51
+ $(this).text("").dequeue();
52
+
53
+ });
54
+
55
+ };
56
+
57
+ });
58
+
59
+ $(window).on('beforeunload',function(){
60
+
61
+ $.cookie('anime',1,{expires:1/24/60/60*5});
62
+
63
+ });
64
+
65
+ </script>
66
+
67
+ <input type="button" id="google" value="google">
68
+
69
+ <input type="button" id="reload" value="reload">
70
+
71
+ <span id="anime"></span>
72
+
73
+ ```