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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

CSS 中指定的變量(高度)但 JS 中未顯示

CSS 中指定的變量(高度)但 JS 中未顯示

嗶嗶one 2023-10-14 18:11:42
我有以下代碼(取自 Wes Bos)。雖然元素的高度是在 CSS 中指定的,但當我嘗試從 JS 訪問它時,它不會出現(xiàn)。當我編寫console.log(bar.style.height)時,它返回空字符串(請參見下面的代碼)。我嘗試尋找其他方法來訪問該值,但沒有成功。我發(fā)現(xiàn)的唯一方法是在 JS 中顯式設置它。有誰知道如何解決這個問題?<!DOCTYPE html><html><head>  <meta charset="UTF-8">  <title>Video Speed Scrubber</title></head><body>  <div class="wrapper">    <video class="flex" width="765" height="430" src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" loop controls></video>    <div class="speed">      <div class="speed-bar">1×</div>    </div>  </div>  <style>    body {  margin: 0;  display: flex;  justify-content: center;  align-items: center;  min-height: 100vh;  background: #4C4C4C url('https://unsplash.it/1500/900?image=1021');  background-size: cover;  font-family: sans-serif;}.wrapper {  width: 850px;  display: flex;}video {  box-shadow: 0 0 1px 3px rgba(0,0,0,0.1);}.speed {  background: #efefef;  flex: 1;  display: flex;  align-items: flex-start;  margin: 10px;  border-radius: 50px;  box-shadow: 0 0 1px 3px rgba(0,0,0,0.1);  overflow: hidden;}.speed-bar {  width: 100%;  background: linear-gradient(-170deg, #2376ae 0%, #c16ecf 100%);  text-shadow: 1px 1px 0 rgba(0,0,0,0.2);  display: flex;  align-items: center;  justify-content: center;  padding: 2px;  color: white;  height: 16.3%;}  </style><script>  const speed = document.querySelector('.speed');  const bar = speed.querySelector('.speed-bar');  const video = document.querySelector('.flex');  console.log(bar.style.height);</script></body></html>
查看完整描述

1 回答

?
撒科打諢

TA貢獻1934條經(jīng)驗 獲得超2個贊

style呈現(xiàn)所選元素的內(nèi)聯(lián)樣式

如果你想獲取CSS值,你需要獲取計算的樣式,使用getComputedStyle

在應用活動樣式表并解析這些值可能包含的任何基本計算之后,該Window.getComputedStyle()方法返回一個包含元素的所有 CSS 屬性值的對象

const speed = document.querySelector('.speed');

const bar = speed.querySelector('.speed-bar');

const video = document.querySelector('.flex');


console.log(getComputedStyle(bar).height);

<!DOCTYPE html>

<html>


<head>

? <meta charset="UTF-8">

? <title>Video Speed Scrubber</title>

? <style>

? ? body {

? ? ? margin: 0;

? ? ? display: flex;

? ? ? justify-content: center;

? ? ? align-items: center;

? ? ? min-height: 100vh;

? ? ? background: #4C4C4C url('https://unsplash.it/1500/900?image=1021');

? ? ? background-size: cover;

? ? ? font-family: sans-serif;

? ? }

? ??

? ? .wrapper {

? ? ? width: 850px;

? ? ? display: flex;

? ? }

? ??

? ? video {

? ? ? box-shadow: 0 0 1px 3px rgba(0, 0, 0, 0.1);

? ? }

? ??

? ? .speed {

? ? ? background: #efefef;

? ? ? flex: 1;

? ? ? display: flex;

? ? ? align-items: flex-start;

? ? ? margin: 10px;

? ? ? border-radius: 50px;

? ? ? box-shadow: 0 0 1px 3px rgba(0, 0, 0, 0.1);

? ? ? overflow: hidden;

? ? }

? ??

? ? .speed-bar {

? ? ? width: 100%;

? ? ? background: linear-gradient(-170deg, #2376ae 0%, #c16ecf 100%);

? ? ? text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.2);

? ? ? display: flex;

? ? ? align-items: center;

? ? ? justify-content: center;

? ? ? padding: 2px;

? ? ? color: white;

? ? ? height: 16.3%;

? ? }

? </style>

</head>


<body>


? <div class="wrapper">

? ? <video class="flex" width="765" height="430" src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" loop controls></video>

? ? <div class="speed">

? ? ? <div class="speed-bar">1×</div>

? ? </div>

? </div>



</body>


</html>


查看完整回答
反對 回復 2023-10-14
  • 1 回答
  • 0 關注
  • 129 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號