第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

我無(wú)法使側(cè)邊欄按鈕在 HTML、CSS 中沿著側(cè)邊欄移動(dòng)

我無(wú)法使側(cè)邊欄按鈕在 HTML、CSS 中沿著側(cè)邊欄移動(dòng)

藍(lán)山帝景 2024-01-03 16:39:07
您好,我正在嘗試為我的網(wǎng)站創(chuàng)建一個(gè)側(cè)邊欄,該側(cè)邊欄具有隨其移動(dòng)的打開(kāi)/關(guān)閉按鈕。我的代碼基于w3school的示例,該示例中有兩個(gè)單獨(dú)的按鈕用于打開(kāi)和關(guān)閉。我不喜歡有兩個(gè)單獨(dú)的按鈕來(lái)完成任務(wù),并且想將它們組合起來(lái)。所以我將示例修改為:如果您嘗試運(yùn)行代碼,那么當(dāng)您第一次單擊該按鈕時(shí),側(cè)邊欄將打開(kāi)并且按鈕也會(huì)隨之打開(kāi)。這很棒,也是我想要的,問(wèn)題是關(guān)閉側(cè)邊欄時(shí)按鈕不會(huì)返回到其原始位置。側(cè)邊欄打開(kāi)和關(guān)閉沒(méi)有問(wèn)題,但似乎這行代碼不起作用document.getElementById("sidebarButton").style.Left = "0px";知道如何修復(fù)它嗎?
查看完整描述

2 回答

?
胡說(shuō)叔叔

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個(gè)贊

盡管樣式屬性在樣式表內(nèi)部不區(qū)分大小寫(xiě),但樣式的 JavaScript API 區(qū)分大小寫(xiě)。因此,設(shè)置style.Left將不起作用,因?yàn)檎_的屬性名稱是left。

document.getElementById("sidebarButton").style.left = '0';


查看完整回答
反對(duì) 回復(fù) 2024-01-03
?
暮色呼如

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊

你有一個(gè)拼寫(xiě)錯(cuò)誤document.getElementById("sidebarButton").style.Left應(yīng)該是document.getElementById("sidebarButton").style.left


var lastState = false;


function sideButtonClicked() {

  if (!lastState) {

    //open

    lastState = true

    document.getElementById("mySidebar").style.width = "250px";

    document.getElementById("main").style.marginLeft = "250px";

    document.getElementById("sidebarButton").style.left = "250px";

  } else {

    //close

    lastState = false

    document.getElementById("mySidebar").style.width = "0px";

    document.getElementById("main").style.marginLeft = "0px";

    document.getElementById("sidebarButton").style.left = "0px";

  }

}

body {

  font-family: "Lato", sans-serif;

}


.sidebar {

  height: 100%;

  width: 0;

  position: fixed;

  z-index: 1;

  top: 0;

  left: 0;

  background-color: #111;

  overflow-x: hidden;

  transition: 0.5s;

  padding-top: 60px;

}


.sidebar a {

  padding: 8px 8px 8px 32px;

  text-decoration: none;

  font-size: 25px;

  color: #818181;

  display: block;

  transition: 0.3s;

}


.sidebar a:hover {

  color: #f1f1f1;

}


.openbtn {

  font-size: 20px;

  cursor: pointer;

  position: fixed;

  bottom: 50%;

  left: 0;

  background-color: #111;

  color: white;

  padding: 10px 15px;

  border: none;

  z-index: 1;

  transition: 0.5s;

}


.openbtn:hover {

  background-color: #444;

}


#main {

  transition: margin-left .5s;

  padding: 16px;

}



/* On smaller screens, where height is less than 450px, change the style of the sidenav (less padding and a smaller font size) */


@media screen and (max-height: 450px) {

  .sidebar {

    padding-top: 15px;

  }

  .sidebar a {

    font-size: 18px;

  }

}

<div id="mySidebar" class="sidebar">

  <a href="#">About</a>

  <a href="#">Services</a>

  <a href="#">Clients</a>

  <a href="#">Contact</a>

</div>


<div id="main">

  <button id="sidebarButton" class="openbtn" onclick="sideButtonClicked()">?</button>

  <h2>Collapsed Sidebar</h2>

  <p>Click on the hamburger menu/bar icon to open the sidebar, and push this content to the right.</p>

</div>


查看完整回答
反對(duì) 回復(fù) 2024-01-03
  • 2 回答
  • 0 關(guān)注
  • 172 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)