Skip to content

Commit be5f8d9

Browse files
committed
feat: self-adaption to PC and Mobile in article page
1 parent 3f55746 commit be5f8d9

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

blog-consumer/src/main/resources/static/js/common.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,17 @@ function topFunction() {
5757
document.documentElement.scrollTop = 0;
5858
}
5959
// ------------------------------------回到顶部 NED ------------------------------------
60+
61+
// ------------------------------------检查客户端的类型 NED ------------------------------------
62+
function clientType() {
63+
if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
64+
//alert("iPhone")
65+
return "iPhone"
66+
} else if (/(Android)/i.test(navigator.userAgent)) {
67+
//alert("Android")
68+
return "Android"
69+
} else {
70+
return "PC"
71+
}
72+
}
73+
// ------------------------------------检查客户端的类型 NED ------------------------------------

blog-consumer/src/main/resources/templates/article.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<body>
6565
<div th:replace="components/nav"></div>
6666

67-
<div class="face article-meta-container">
67+
<div class="face article-meta-container" id="articleMetaDiv">
6868
<h1 th:text="${articleVo.title}">title</h1>
6969

7070
<p>
@@ -83,7 +83,7 @@ <h1 th:text="${articleVo.title}">title</h1>
8383
</div>
8484
</div>
8585

86-
<div class="face">
86+
<div class="face" id="articleMainDiv">
8787
<!--左侧导航栏-->
8888
<aside>
8989
</aside>
@@ -105,7 +105,7 @@ <h1 th:text="${articleVo.title}">title</h1>
105105
</div>
106106

107107
<!--评论区-->
108-
<div class="face article-comment-container">
108+
<div class="face article-comment-container" id="articleCommentDiv">
109109
<!--评论-->
110110
<div class="add-comment-container" th:if="${articleVo.commented != null && articleVo.commented}">
111111
<p style="text-align: center; font-size: x-large">留下你的评论</p>
@@ -192,6 +192,16 @@ <h1 th:text="${articleVo.title}">title</h1>
192192
<script src="/js/common.js"></script>
193193
<script>
194194
$(function () {
195+
//检查浏览器类型,移除仅在PC端才会显示的元素
196+
let type = clientType()
197+
if("PC" !== type) {
198+
$("#articleMetaDiv").removeClass("face")
199+
$("#articleMainDiv").removeClass("face")
200+
$("#articleCommentDiv").removeClass("face")
201+
202+
$("aside").remove()
203+
}
204+
195205
//当出现滚动时,就检测一下,是否需要显示回到顶部按钮
196206
window.onscroll = function () {
197207
scrollFunction();

0 commit comments

Comments
 (0)