【发布时间】:2019-08-31 06:57:16
【问题描述】:
我正在尝试创建自己的Radio Button。我创建了一个Switch 原型,但我无法选择this div.radio_button 的:before。如何将:before 查询到变量中?
HTMLDivElement.prototype.Switch = function() {
if ((this.getAttribute("class") == "radio_button")) {
var s = this.querySelector("::before"); // s being null
console.log(s);
}
};
HTMLDivElement.prototype.selected = false;
document.querySelector("div.radio_button").Switch();
div.radio_button {
height: 30px;
width: 50px;
background-color: rgb(190, 190, 190);
-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
-moz-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
-webkit-border-radius: 25px;
-moz-border-radius: 25px;
border-radius: 25px;
position: relative;
margin: 0;
-webkit-transition: 0.5s;
transition: 0.5s;
}
div.radio_button:before {
content: '';
height: 30px;
width: 30px;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
-webkit-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
position: absolute;
top: 0;
left: 0;
background-color: rgb(255, 255, 255);
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-ms-transform: scale(1.1);
-o-transform: scale(1.1);
transform: scale(1.1);
-webkit-transition: 0.5s;
transition: 0.5s;
}
<div class="radio_button"></div>
【问题讨论】:
-
没有找到任何有用的东西
标签: javascript css