<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0px;
padding: 0;
}
body {
height: 3000px;
}
.header {
width: 100%;
height: 40px;
background-color: skyblue;
font-size: 30px;
text-align: center;
position: fixed;
top: -40px;
/* top: 0; */
left: 0;
/* display: none; */
transition: top 0.5s linear;
}
.go {
width: 50px;
height: 50px;
background-color: yellow;
font-size: 20px;
line-height: 25px;
text-align: center;
position: fixed;
bottom: 80px;
right: 80px;
display: none;
}
</style>
</head>
<body>
<div id="header" class="header">頂部通欄</div>
<div id="go" class="go">返回頂部</div>
<script>
/*
需求 隨著滾動條決定 頂部通欄 和 回到頂部 按鈕的顯示和隱藏
分析:
=> 要隨著滾動條的滾動 就要有一個滾動條的滾動事件了
=> 當滾動條的滾動的時候卷去的高度大于等于300的時候顯示
=> 也就是小于300的時候是隱藏的
*/
//實現(xiàn)
window.onscroll = function () {
// console.log(111);
// 獲取頁面卷去的高度
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
// 判斷頁面卷去的高度是多少根據(jù)值的不同設置顯示還是隱藏
if (scrollTop >= 300) {
header.style.display = 'block'
go.style.display = 'block'
} else {
header.style.display = 'none'
go.style.display = 'none'
}
}
// 有效果的實現(xiàn)
window.onscroll = function () {
// console.log(111);
// 獲取頁面卷去的高度
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
// 判斷頁面卷去的高度是多少根據(jù)值的不同設置顯示還是隱藏
console.log(scrollTop);
if (scrollTop >= 300) {
header.style.top = '0'
go.style.display = 'block'
} else {
header.style.top = '-40px'
go.style.display = 'none'
}
}
</script>
</body>
</html>

北京市人力資源和社會保障局、北京市人才工作局近日發(fā)布了關于印發(fā)《北京市境外職業(yè)資格認可目錄(3.0版)》的通知,新版目錄境外職業(yè)資格清單...詳情>>
2023-09-07 17:27:00
怎么選擇靠譜的短視頻運營培訓機構?5G時代的來臨,短視頻作為新媒體中最為主流的內容更加方便用戶瀏覽觀看信息,因此抖音、快手這類的短視頻平...詳情>>
2023-09-07 15:05:06
全媒體短視頻運營好就業(yè)么?現(xiàn)在學習互聯(lián)網運營可不能只會單個的運營技術,企業(yè)更喜歡全能型人才。如今的互聯(lián)網世界有多種平臺,新媒體、短視頻...詳情>>
2023-09-07 14:49:25
短視頻運營培訓機構有用嗎?短視頻的火熱,催生了一大批的網絡紅人、網紅賬號,這些短視頻賬號通過實現(xiàn)粉絲流量變現(xiàn),獲得了非常豐厚的收入,自...詳情>>
2023-09-06 13:49:12
大數(shù)據(jù)分析就業(yè)高薪崗位介紹?大數(shù)據(jù)行業(yè)是一個快速發(fā)展的行業(yè),其主要特征是數(shù)據(jù)規(guī)模龐大、種類多樣、處理復雜。目前,大數(shù)據(jù)行業(yè)已經成為全球...詳情>>
2023-09-06 13:42:47