【问题标题】:CSS circular menu <a href>CSS 圆形菜单 <a href>
【发布时间】:2015-10-04 02:50:32
【问题描述】:

我想添加指向 https://jsfiddle.net/zv5dr670/4/ 上的循环菜单的链接。

<a href="http://www.google.com" target="_blank">
  <li>
    <input id='1' type='checkbox'>
    <label for='1'>Option 1</label>
  </li>
</a>

链接显示在浏览器状态栏中,但不会对点击做出反应。我现在不在学校工作 CSS,只有 HTML。你能帮帮我吗?

【问题讨论】:

  • 在小提琴中menu1,menu2 ....ve变成链接了吗??
  • ???你需要一个链接才能点击它:p 或者我不明白你?! jsfiddle.net/zv5dr670/15

标签: css hyperlink menu


【解决方案1】:

您可以向li 元素添加自定义属性,如下所示

<li class='link' data-url='https://jsfiddle.net'>
  <input id='c1' type='checkbox'/>
  <label for='c1'>Menu 1</label>
</li>

然后使用 jQuery,您可以像这样绑定link 类'click event

$('li.link').click(function(e) {
    window.location=$(this).attr('data-url');
});

【讨论】:

    【解决方案2】:

    如果你想制作外圈只是链接,你不必使用输入标签:

    HTML

    <div class='selector'>
      <ul>
        <li><a href="http://google.com/">Google</a></li>
        <li><a href="http://google.com/">Google</a></li>
        <li><a href="http://google.com/">Google</a></li>
        <li><a href="http://google.com/">Google</a></li>
        <li><a href="http://google.com/">Google</a></li>
        <li><a href="http://google.com/">Google</a></li>
        <li><a href="http://google.com/">Google</a></li>
        <li><a href="http://google.com/">Google</a></li>
        <li><a href="http://google.com/">Google</a></li>
      </ul>
      <button>Click</button>
    </div>
    <button class ="mycbutton">Click2</button>
    

    CSS

    html,
    body { height: 100%; }
    body {
      margin: 0;
      background: linear-gradient(#eeeeee, #cccccc);
      overflow: hidden;
    }
    .mycbutton {
    
    }
    .selector {
      position: absolute;
      left: 50%;
      top: 50%;
      width: 140px;
      height: 140px;
      margin-top: -70px;
      margin-left: -70px;
    }
    .selector,
    .selector button {
      font-family: 'Oswald', sans-serif;
      font-weight: 300;
    }
    .selector button {
      float:right;
      position: relative;
      width: 100%;
      height: 100%;
      padding: 10px;
      background: #428bca;
      border-radius: 50%;
      border: 0;
      color: white;
      font-size: 20px;
      cursor: pointer;
      box-shadow: 0 3px 3px rgba(0, 0, 0, 0.1);
      transition: all .1s;
    }
    .selector button:hover { background: #3071a9; }
    .selector button:focus { outline: none; }
    .selector ul {
      position: absolute;
      list-style: none;
      padding: 0;
      margin: 0;
      top: -20px;
      right: -20px;
      bottom: -20px;
      left: -20px;
    }
    .selector li {
      position: absolute;
      width: 0;
      height: 100%;
      margin: 0 50%;
      -webkit-transform: rotate(-360deg);
      transition: all 0.8s ease-in-out;
    }
    .selector li a {
      position: absolute;
      left: 50%;
      bottom: 100%;
      width: 0;
      height: 0;
      line-height: 1px;
      margin-left: 0;
      background: #fff;
      border-radius: 50%;
      text-align: center;
      font-size: 1px;
      overflow: hidden;
      cursor: pointer;
      box-shadow: none;
      transition: all 0.8s ease-in-out, color 0.1s, background 0.1s;
      text-decoration: none;
      color: black;
    }
    .selector li a:hover { background: #f0f0f0; }
    .selector.open li a {
      width: 80px;
      height: 80px;
      line-height: 80px;
      margin-left: -40px;
      box-shadow: 0 3px 3px rgba(0, 0, 0, 0.1);
      font-size: 14px;
    }
    

    JS

    var nbOptions = 9;
    var angleStart = -360;
    
    // jquery rotate animation
    function rotate(li,d) {
        $({d:angleStart}).animate({d:d}, {
            step: function(now) {
                $(li)
                   .css({ transform: 'rotate('+now+'deg)' })
                   .find('a')
                      .css({ transform: 'rotate('+(-now)+'deg)' });
            }, duration: 0
        });
    }
    
    // show / hide the options
    function toggleOptions(s) {
        $(s).toggleClass('open');
        var li = $(s).find('li');
        var deg = $(s).hasClass('half') ? 180/(li.length-1) : 360/li.length;
        for(var i=0; i<li.length; i++) {
            var d = $(s).hasClass('half') ? (i*deg)-90 : i*deg;
            $(s).hasClass('open') ? rotate(li[i],d) : rotate(li[i],angleStart);
        }
    }
    
    $('.selector button').click(function(e) {
        toggleOptions($(this).parent());
    });
    
    $('.mycbutton').click(function(e) {
        toggleOptions($(this).parent());
    });
    
    setTimeout(function() { toggleOptions('.selector'); }, 100);
    

    JSFiddle上运行它

    【讨论】:

      猜你喜欢
      • 2015-03-31
      • 2017-08-28
      • 1970-01-01
      • 2014-02-19
      • 2016-11-20
      • 1970-01-01
      • 2020-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多