gpt4 book ai didi

javascript - 在 FireFox 和 Chrome 中工作但在 Internet Explorer 中不工作的脚本

转载 作者:行者123 更新时间:2023-11-28 15:44:24 25 4
gpt4 key购买 nike

<div class="btn-slides-labels">      
<input class="btn fa-input" type="submit" value="Download">
<span id="top-label" class="top-label">Downloads : 1546 Times</span>
<span id="bottom-label" class="bottom-label">1.2MB .zip</span>
</div>

我想根据按钮“btn fa-input”的宽度动态修改元素顶部标签和底部标签的宽度。

但这两个标签的宽度在 FireFox 和 Chrome 中正常工作,但在 Internet Explorer 中除外。

DEMO

var element = document.getElementsByClassName('btn fa-input');
for(var i = 0; i < element.length; i++) {
var btnWidth = element[i].offsetWidth;
var btnHeight = element[i].offsetHeight;
var toplabel = element[i].closest('div').childNodes[3];
var bottomlabel = element[i].closest('div').childNodes[5];
toplabel.style.width = btnWidth-20+'px';
bottomlabel.style.width = btnWidth-20+'px';

}
body {
margin-top: 100px;
text-align: center;
}
.btn-slides-labels {
display: inline-block;
}
.top-label, .bottom-label {
margin: -50px 0 0 10px;
background: #222;
display: block;
height: 40px;
text-align: center;
font: 12px/45px Helvetica, Verdana, sans-serif;
color: #fff;
position: absolute;
z-index: -1;
box-sizing : border-box;

}
.bottom-label {
-webkit-border-radius: 10px 10px 0px 0px;
-moz-border-radius: 10px 10px 0px 0px;
border-radius: 10px 10px 0px 0px;
-webkit-transition: margin 0.5s ease;
-moz-transition: margin 0.5s ease;
-o-transition: margin 0.5s ease;
-ms-transition: margin 0.5s ease;
transition: margin 0.5s ease;
line-height: 35px;
}
.top-label {
-webkit-border-radius: 0px 0px 10px 10px;
-moz-border-radius: 0px 0px 10px 10px;
border-radius: 0px 0px 10px 10px;
-webkit-transition: margin 0.5s ease;
-moz-transition: margin 0.5s ease;
-o-transition: margin 0.5s ease;
-ms-transition: margin 0.5s ease;
transition: margin 0.5s ease;
line-height: 45px;
}

/* HOVER */
.btn-slides-labels:hover .bottom-label {
margin: -100px 0 0 10px;
}

.btn-slides-labels:hover .top-label {
margin: -20px 0 0 10px;
/*line-height: 50px;*/
}

.btn {
text-align: center;
background: #dd3333;
color: #f7f7f7;
font-size: 023px;
border-radius: 005px;
padding: 15px 35px;
box-shadow: 0 -003px rgba(0, 0, 0, 0.14) inset;
display: inline-block;
text-transform: uppercase;
text-decoration: none;
margin: 10px 0px;
transition: all 0.2s linear 0s;
-moz-transition: all 0.2s linear 0s;
-webkit-transition: all 0.2s linear 0s;
-o-transition: all 0.2s linear 0s;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-o-border-radius: 5px;
box-shadow: 0 -4px rgba(0, 0, 0, 0.14) inset;
-moz-box-shadow: 0 -4px rgba(0, 0, 0, 0.14) inset;
-webkit-box-shadow: 0 -4px rgba(0, 0, 0, 0.14) inset;
-o-box-shadow: 0 -4px rgba(0, 0, 0, 0.14) inset;
letter-spacing: 1.5px;
border: none;
cursor: pointer;
}

.btn:hover {
background: #2ecc71;
}
<div class="btn-slides-labels">      
<input class="btn fa-input" type="submit" value="Download">
<span id="top-label" class="top-label">Downloads : 1546 Times</span>
<span id="bottom-label" class="bottom-label">1.2MB .zip</span>
</div>

<div class="btn-slides-labels">
<input class="btn fa-input" type="submit" value="Download">
<span id="top-label" class="top-label">Downloads : 1546 Times</span>
<span id="bottom-label" class="bottom-label">1.2MB .zip</span>
</div>

最佳答案

IE/Edge 不支持

Element.closest()
这是一个 polyfill:

if (window.Element && !Element.prototype.closest) {
Element.prototype.closest =
function(s) {
var matches = (this.document || this.ownerDocument).querySelectorAll(s),
i,
el = this;
do {
i = matches.length;
while (--i >= 0 && matches.item(i) !== el) {};
} while ((i < 0) && (el = el.parentElement));
return el;
};
}

无耻地敲竹杠MDN .

关于javascript - 在 FireFox 和 Chrome 中工作但在 Internet Explorer 中不工作的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43046308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com