自己重構一個非常簡單的網頁
阿新 • • 發佈:2021-01-19
技術標籤:小專案經驗
剛剛學完HTML\CSS\以及JS之後看到網上有一個漁樂科技的官網比較簡潔而且好看就去聯絡重構了一下他的主頁。積累了一些知識
介面重構方面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" >
<title>Document</title>
<style>
body {
margin: 0;
}
header {
position: fixed;
width: 100vw;
height: 84px;
top: 0;
left: 0;
z-index: 1;
/*文件流在0層*/
}
header.white>div{
background-color: white;
box-shadow: 0px 0px 5px rgb(0, 0, 0, 0.5);
color: black;
text-shadow: 0 0 0px #cccccc;
}
header>div {
background-color: transparent;
transition: background-color 1s ;
height: 84px;
position: relative;
overflow: hidden;
color: white;
text-shadow: 0 0 5px #cccccc;
}
header>div>img {
position: absolute;
width: 40px;
height: 40px;
margin-top: 20px;
margin-left: 95px;
border-radius: 10px;
}
header>div>span {
position: absolute;
margin-left: 140px;
margin-top: 23px;
font-size: 25px;
}
header>div>div {
position: absolute;
width: 100px;
height: 56px;
right: 210px;
margin-top: 0px;
/* background-color: white; */
text-align: center;
font-size: 20px;
padding-top: 28px;
}
header>div>div+div {
position: absolute;
width: 100px;
height: 56px;
right: 110px;
margin-top: 0px;
/* background-color: white; */
text-align: center;
font-size: 20px;
padding-top: 28px;
}
header>div>div+div+div {
position: absolute;
width: 100px;
height: 56px;
right: 10px;
margin-top: 0px;
/* background-color: white; */
text-align: center;
font-size: 20px;
padding-top: 28px;
}
.change_img {
opacity: 0;
transition: opacity 1s ease-in-out;
}
.change_img.active {
opacity: 1;
}
#img-box {
position: relative;
}
ul{
list-style: none;
padding-left: 0;
position: relative;
width: 100vw;
height: calc(100vw*3/4);
margin-bottom: 0px;
margin-top: 0px;
}
li{
position: absolute;
width: 100%;
overflow: hidden;
}
.change_img {
width: 100vw;
}
#text-box {
display: flex;
flex-direction: column;
background-color: white;
height: 1300px;
position: relative;
width: 80vw;
margin: 0 auto;
}
.in-text-box {
flex: 1;
background-color: white;
border-top: 1px solid rgb(216, 210, 210);
margin-right: 20vw;
text-align: center;
width: 80vw;
}
</style>
</head>
<body>
<header>
<div>
<img src="../2021.1.11小專案漁樂官網/img/漁樂Logo.jpg" alt="">
<span>漁樂科技</span>
<div>首頁</div>
<div>產品</div>
<div>關於</div>
</div>
</header>
<div id="img-box">
<ul>
<li>
<img class="change_img active" src="img/banner.png" alt="">
</li>
<li>
<img class="change_img " src="img/IMG_9463-5.jpg" alt="">
</li>
<li>
<img class="change_img " src="img/top-img-3.jpg" alt="">
</li>
</ul>
</div>
<div id="text-box">
<div class="in-text-box" style="margin-right: 0vw;margin-left: 0vw;">
<h3 style="margin-top: 100px; font-size: 50px;">戰略佈局</h3>
<div style="display: flex;margin-top: 100px;width: 80vw;margin-left:auto ;">
<div style="flex:1; ">
<img src="../2021.1.11小專案漁樂官網/img/漁樂Logo.jpg" alt="" style="width: 100px; height: 100px; flex: 1;">
<h3 style="font-size: 30px;margin-top: 10px;margin-bottom: 10px;">社群</h3>
<p style="display: inline-block;margin-top: 0px;">
以解決具體使用者群的痛點為導向,在已有使用者群的<br>基礎上細化使用者畫像、建造、分類、管理5G時代<br>下的精細資料化社群運營</p>
</div>
<div style="flex: 1;">
<img src="../2021.1.11小專案漁樂官網/img/漁樂Logo.jpg" alt="" style="width: 100px; height: 100px; flex: 1;">
<h3 style="font-size: 30px;margin-top: 10px;margin-bottom: 10px;">文娛</h3>
<p style="display: inline-block;margin-top: 0px;">
以高新技術的應用為導向,將時代前沿的科學技術<br>以最廣泛接受的方式運用至人們的日常生活,在<br>提升生活品質的同時,也增添生活樂趣。</p>
</div>
<div style="flex: 1;">
<img src="../2021.1.11小專案漁樂官網/img/漁樂Logo.jpg" alt="" style="width: 100px; height: 100px; flex: 1;">
<h3 style="font-size: 30px;margin-top: 10px;margin-bottom: 10px;">資料</h3>
<p style="display: inline-block;margin-top: 0px;">
以資料分析及演算法商業化為導向,將已有的資料進<br>行二次提取分析,並加以具體的應用場景及實際<br>使用場合,讓使用者便利於資料的精準傳播。</p>
</div>
</div>
</div>
<div class="in-text-box" style="display: flex;">
<div style="text-align: left;margin-left: 0vw; margin-right: 0vw; width: 50vw; flex:6;">
<h3 style="font-size: 50px;">近期新聞</h3>
<p>1. 漁樂科技社群類專案Ufun近期將於山西省內展開試運營。 <br>2. 山西漁樂科技有限責任公司,2020年經山西股權交易中心批准,現已在山西青創版掛牌展示。</p>
</div>
<img src="img/board2-img-1.jpg" alt=""
style="width: 319px;height: 242px; flex: 4;margin-top: 3vw;margin-bottom: 5vw;">
</div>
<div class="in-text-box" style="display:flex;">
<img src="img/board2-img-2.png" alt=""
style="width: 319px;height: 260px; flex: 4; margin-top: 3vw;margin-bottom: 5vw;">
<div style="text-align: left; margin-left: 3vw; margin-right: 0vw; width: 45vw; flex:6;">
<h3 style="font-size: 50px; text-align: right;">產品動態</h3>
<p>1. Ufun近期將開啟第二輪內測,內測版本為1.15V,預計將在6月開啟為期3個月的試運營。<br> 2.
代號為“Ufun”的專案,在山西大學軟體學院、西安建築科技大學安德學院內開啟測試,目前使用者累計開辦講座16場,總觀看人數3029人。</p>
</div>
</div>
</div>
<footer style="width: 100vw; height: calc(100vw*1/5); background-color: #424242; display:flex;">
<div style="flex:6;margin-left: 10vw;color: white;">
<h2>漁樂科技</h2>
<p> 用科技造福社會</p>
<p style="margin-top: 50px;">© 2020 Copyright 山西漁樂科技有限責任公司</p>
<p><img src="img/gong-an-logo_.png" style="width:15px; height:15px"> 晉公網安備 14019202000616號 晉ICP備 20004422號-1
</p>
</div>
<div style="flex:4;color: white;">
<h2>連結</h2>
<p>網站地圖</p>
<p>聯絡我們</p>
</div>
</footer>
</body>
</html>
整體的佈局分為了頂部欄(
- 頂部欄是比較容易,一個簡單的佈局
- 之後的圖片展示欄選擇了使用ul和li標籤來進行圖片的儲存,方便管理和之後的新增
- 文章展示區域有三部分採用flex將他們等分,而且在第一個欄中,將任榮橫向的用flex等分。
- 底部欄將左邊有右邊設定兩個div分割,用flex4/6分割
當然我們其實可以不規定大小和等分,而是利用每個中間的元素就擠壓使外部div發生大小的改變,這樣的網站更加的靈活而且佈局遇到改變,修改起來也比較方便
邏輯實現
<script>
setInterval(function () {
let arr = document.querySelectorAll('.change_img');//選擇選擇器
for (let i = 0; i < arr.length; i++) {
if (arr[i].classList.contains("active")) {
arr[i].classList.remove("active");
i = (i + 1) % arr.length;
arr[i].classList.add('active');
break;
}
}
}, 2000);
window.onscroll = function () {
//為了保證相容性,這裡取兩個值,哪個有值取哪一個
//scrollTop就是觸發滾輪事件時滾輪的高度
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
let width = document.body.clientWidth;
let header = document.getElementsByTagName('header');
scrollTop = parseInt(scrollTop);
console.log(parseInt(width*3/4));
console.log(scrollTop);
if(scrollTop > parseInt(width*3/4)){
console.log(header);
header[0].classList.add('white');
}
else{
header[0].classList.remove('white');
}
}
</script>
- 圖片的輪播我們使用一個
setInterval()
h函式來實現,將它2秒一次重新整理,重新整理時通過控制給圖片新增類名來修改圖片的樣式,從而實現圖片的輪播
- 第二個樣式是頂部導航欄在滑動到text部分的時候由透明變為白色。
- 首先我們的header要具有
z-index: 1;
屬性,置於文件流的0層(置頂) - 之後我們繫結滾輪滑動的監聽事件
window.onscroll = function ()
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
獲取導航欄滾動的距離let width = document.body.clientWidth;
獲取body的實際高度。- 根據除錯可以看到,當走過body的實際高度的3/4的時候應該改變,我們還是通過新增類名改變選擇器來改變樣式。
這樣我們就粗略的完成了主頁的繪製了