尝试使用JavaScript和HTML / CSS显示文本

时间:2019-03-20 07:06:20

标签: javascript html css

我使用的是目前已设置样式且看起来不错的“切换器”。

我想要的是,当切换器向右滑动时,会在页面上打印DIV。

我在页面上找不到错误...

这是CSS

void cubeBox(float x, float y, float z) {

    translate(x, y, z);
    addRotation();

    // [...]

}
function toggleDiv() {
  if (document.getElementById('myonoffswitch').checked) {
    document.querySelector('.triggeredDiv').classList.remove('hidden');
  } else {
    document.querySelector('.triggeredDiv').classList.add('hidden');
  }
}
document.getElementById('myonoffswitch').addEventListener("change", toggleDiv);
.onoffswitch {
        position: relative; width: 200px;
        -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
    }
    .onoffswitch-checkbox {
        display: none;
    }
    .onoffswitch-label {
        display: block; overflow: hidden; cursor: pointer;
        border: 2px solid #999999; border-radius: 20px;
    }
    .onoffswitch-inner {
        display: block; width: 200%; margin-left: -100%;
        transition: margin 0.3s ease-in 0s;
    }
    .onoffswitch-inner:before, .onoffswitch-inner:after {
        display: block; float: left; width: 50%; height: 51px; padding: 0; line-height: 51px;
        font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
        box-sizing: border-box;
    }
    .onoffswitch-inner:before {
        content: "MONTHLY LIST";
        padding-left: 10px;
        background-color: #dfe4ea; color: #999999;
    }
    .onoffswitch-inner:after {
        content: "BY COUNTRY";
        padding-right: 10px;
        background-color: #dfe4ea; color: #999999;
        text-align: right;
    }
    .onoffswitch-switch {
        display: block; width: 50px; margin: 0.5px;
        background: #A1A1A1;
        position: absolute; top: 0; bottom: 0;
        right: 145px;
        border: 2px solid #999999; border-radius: 20px;
        transition: all 0.3s ease-in 0s;
    }
    .onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
        margin-left: 0;
    }
    .onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
        right: 0px;
        background-color: #999999;
    }
    .triggeredDiv {
  display: block;
}

.triggeredDiv.hidden {
  display: none;
}

我相信CSS的某些“隐藏”在这里:

     <div class="onoffswitch">
        <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
        <label class="onoffswitch-label" for="myonoffswitch">
                <span class="onoffswitch-inner"></span>
                <span class="onoffswitch-switch"></span>
            </label>
      </div>

  <div class="triggeredDiv">
    Hello World
  </div>

任何人都可以看到错误或缺失的内容吗?

这篇文章是this request for help.

的前身

顺便说一下,实际的切换器生成器在这里:https://proto.io/freebies/onoff/

1 个答案:

答案 0 :(得分:0)

好的,我通过在页面底部添加JavaScript来“修复”它。我想那是错的-对吗?