溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何使用HTML5實(shí)現(xiàn)滾動(dòng)條滑動(dòng)效果

發(fā)布時(shí)間:2022-03-01 10:41:59 來源:億速云 閱讀:683 作者:小新 欄目:開發(fā)技術(shù)

這篇文章將為大家詳細(xì)講解有關(guān)如何使用HTML5實(shí)現(xiàn)滾動(dòng)條滑動(dòng)效果,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

背景圖鋪滿頁面,他要求有滾動(dòng)條可以滑動(dòng),他給我講的思路是用js 獲取背景圖片的高,在獲取當(dāng)前窗口的高,兩者比較,當(dāng)窗口的高小于背景圖片的高,把窗口的高設(shè)置成背景顏色的高。反之就是窗口的高。 感覺太麻煩,用css就可以實(shí)現(xiàn)他的要求:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">       
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<title>長背景圖測試/title>
<style type="text/css">
        //body里面的屬性min-height是關(guān)鍵,網(wǎng)上說直接設(shè)置成100vh即可,如果不可以可以自己微調(diào)
    body{
        background:url(./images/download_bg.png) no-repeat;
        background-size:100%;
                //方案1
        min-height: 185vh;
                //方案2,本質(zhì)等價(jià)于方案一,如果兩個(gè)方案是同時(shí)開啟,則會(huì)使用高度更小的那個(gè),已測試
                //height:1200px;
    }
 
    #btn{
        margin-top: 150px;
        text-align: center;
    }  
     
</style>
<body>
 
<div id="btn">
    <a href=" http://www.cnblogs.com/fanbi">
    <img src="./images/download_btn.png" width="90%" alt="跳轉(zhuǎn)到某個(gè)網(wǎng)頁地址"/></a>
</div>   
 
</body>
</html>

這是網(wǎng)上找的代碼。

我改動(dòng)了下:

body{
    background: -webkit-linear-gradient(to bottom , #699eef, #8e92ef); 
    background: -o-linear-gradient(to bottom , #699eef, #8e92ef); 
    background: -moz-linear-gradient(to bottom , #699eef, #8e92ef); 
    background: linear-gradient(to bottom , #699eef, #8e92ef);
  
}
.app {
    width: 100%;
    /* height:900px; */
    min-height: 120vh;
    /* position: fixed; */
    /* top: 0; */
    /* left: 0; */
    background: url('../../images/bg.jpg') no-repeat;
    background-size: 100% auto;
    
}

給body加了個(gè)跟圖片顏色一樣的背景色

解決問題。

關(guān)于“如何使用HTML5實(shí)現(xiàn)滾動(dòng)條滑動(dòng)效果”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI