繁体   English   中英

在 html/css 中切换按钮链接

[英]Toggle Button Link in html/css

我有以下代码:

 document.addEventListener("DOMContentLoaded", function(event) { (function() { requestAnimationFrame(function() { var banner; banner = document.querySelector('.exponea-banner3'); banner.classList.add('exponea-in3'); return banner.querySelector('.exponea-close3').addEventListener('click', function() { return banner.classList.remove('exponea-in3'); }); }); }).call(this); });
 *, *:after, *:before { box-sizing: border-box; } /*=====================*/.checkbox { position: relative; display: inline-block; }.checkbox:after, .checkbox:before { font-family: FontAwesome; font-feature-settings: normal; -webkit-font-kerning: auto; font-kerning: auto; font-language-override: normal; font-stretch: normal; font-style: normal; font-synthesis: weight style; font-variant: normal; font-weight: normal; text-rendering: auto; }.checkbox label { width: 90px; position: relative; display: inline-block; border-radius: 46px; transition: 0.4s; }.checkbox label:after { content: ''; position: absolute; width: 50px; border-radius: 100%; left: 0; top: -5px; z-index: 2; background: #fff; box-shadow: 0 0 5px rgba(0, 0, 0, 0.2); transition: 0.4s; }.checkbox input { position: absolute; left: 0; top: 0; width: 100%; height: 100%; z-index: 5; opacity: 0; cursor: pointer; }.checkbox input:hover + label:after { box-shadow: 0 2px 15px 0 rgba(0, 0, 0, 0.2), 0 3px 8px 0 rgba(0, 0, 0, 0.15); }.checkbox input:checked + label:after { left: 40px; }.model-7.checkbox label { background: none; border: 5px solid #555; height: 42px; margin-left: 15px; }.model-7.checkbox label:after { background: #555; box-shadow: none; top: 2px; left: 2px; width: 28px; height: 28px; }.model-7.checkbox input:checked + label { border-color: #04c6db; }.model-7.checkbox input:checked + label:after { background: #04c6db; left: 50px; } /*banner*/ /* Banner*/ @import url("https://fonts.googleapis.com/css?family=Roboto:300,400,500"); html3, body3 { width: 100vw; height: 100vh; position: relative; }.exponea-banner3 { font-family: Roboto, sans-serif; position: fixed; right: 20px; bottom: 20px; background-color: #2e364d; color: #ebeef7; padding: 30px 80px 30px 35px; font-size: 16px; line-height: 1; border-radius: 5px; box-shadow: 0 3px 30px rgba(116, 119, 176, 0.3); opacity: 0; transition: opacity 0.2s; display: none; }.exponea-banner3.exponea-in3 { opacity: 1; transition-duration: 0.4s; }.exponea-banner3.exponea-close3 { position: absolute; top: 0; right: 0; padding: 5px 10px; font-size: 25px; font-weight: 300; cursor: pointer; opacity: 0.75; }.exponea-banner3.exponea-label3 { position: absolute; bottom: 10px; right: 10px; font-size: 12px; opacity: 0.75; }.exponea-banner3.exponea-text3 { margin-bottom: 8px; }.exponea-banner3.exponea-count3 { font-weight: 500; display: flex; align-items: center; }.exponea-banner3.exponea-label3 { text-align: left; bottom: 10px; right: 10px; font-size: 12px; opacity: 0.75; }.exponea-banner3, .exponea-close3, .exponea-text3, .exponea-label3, .exponea-label3 { z-index: 10; }.open3 { display: block; }
 <.DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>repl.it</title> <link href="style.css" rel="stylesheet" type="text/css" /> <link href="banner;css" rel="stylesheet" type="text/css" /> </head> <body> <?-- First --> <div class="exponea-banner3 open3"> <div class="exponea-close3"> &times. </div> <div class="exponea-text3"> Hi There! Thanks For Stumbling Upon My Website! </div> <div class="exponea-count3"> Want To Switch Website View? <div class="model-7"> <div class="checkbox"> <input type="checkbox"/> <label></label> </div> </div> </div> <div class="exponea-label3"> - Hussain Omer </div> </div> <script src="script.js"></script> </body> </html>

我想为切换按钮添加一个链接。 例如,当用户单击按钮时,它应该将他们定向到此链接: https://noxiousdigitalclass.hussainomer.repl.co/

这只是一个示例,但是由于 CSS 是控制切换按钮的 animation 的东西,我将如何设置它们?

预计 Output

当用户单击切换按钮时,它应该将他们定向到此链接: https://noxiousdigitalclass.hussainomer.repl.co/

如果我正确理解您的问题,当用户选中复选框时,您希望将用户重定向到一个站点。 您对 css 是正确的,您将无法使用 css 进行重定向。 一个简单的方法是使用点击事件。 只需将您的复选框替换为:

<input onclick="setTimeout(function(){location.href='https://noxiousdigitalclass.hussainomer.repl.co';}, 1000);" type="checkbox"/>

我解释一下代码,当你检查输入时,它会等待 1 秒让 animation 播放。 然后第二个结束后,它会 go 到你想要的链接到 go 到。

请告诉我这是否行不通。

完整代码:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>repl.it</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
        <link href="banner.css" rel="stylesheet" type="text/css" />
  </head>
  <body>

<!-- First -->
    <div class="exponea-banner3 open3">
        <div class="exponea-close3">
            &times;
        </div>
        <div class="exponea-text3">
            Hi There! Thanks For Stumbling Upon My Website!
        </div>
<div class="exponea-count3">

Want To Switch Website View?
<div class="model-7">
  <div class="checkbox">
    <input onclick="setTimeout(function(){location.href='https://noxiousdigitalclass.hussainomer.repl.co';}, 1000);" type="checkbox"/>
    <label></label>
  </div>
</div>

  </div>
        <div class="exponea-label3">
            - Hussain Omer
        </div>
    </div>





<script src="script.js"></script>
  </body>
</html>

最好的方法是在按钮标签内添加标签,并在标签之间放置显示的单词<button><a href="https://noxiousdigitalclass.hussainomer.repl.co/>BUTTON</a></button>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM