简体   繁体   English

如果单击圆圈,如何将圆圈与线条垂直连接起来,它应该用颜色填充

[英]how to connect circles with line vertically if clicked on circle it should fill with color

I want to create structure as shown in the image below with unordered list item if user click on the list item the circle should fill with color.如果用户单击列表项,圆圈应该用颜色填充,我想创建如下图所示的结构,其中包含无序列表项。 i have created on div inside that i have took list items and inside list span element.I user clicks on first list item the circle should fill with color if i click on another list then it should fill with color just like active or focus on links in menubar我在 div 里面创建了我已经获取了列表项和列表跨度元素。我用户点击第一个列表项,如果我点击另一个列表,圆圈应该用颜色填充,然后它应该用颜色填充,就像活动或专注于链接一样在菜单栏中

Here is what i have to achieve Here is what i want to achieve这是我必须实现的目标这是我想要实现的目标

Here what i have tried这是我尝试过的

    <div class="sizes">
    <ul>
      <li class="dot"><span></span>6"x6" | 599</li>
      <li class="dot"><span></span>12"x12" | 799</li>
      <li class="dot"><span></span>12"x18" | 999</li>
      <li class="dot"><span></span>18"x12" | 799</li>
      <li class="dot"><span></span>16"x20" | 1,399</li>
    </ul>
</div>

css css

.shop-all .product-content ul li {
    position:relative;
    font-family: 'Lato';
    font-size: 16px;
    font-weight: bold;
    padding: 10px 0 10px 0;
    cursor: pointer;}

    .shop-all .product-content ul li span {
      border-radius: 50%;
      border: 1px solid #d95d5d;
      padding: 2px 10px;
      margin-right: 10px;
      background-color:#fff;
    }

    .shop-all .product-content ul li span.filled {
        background-color: #d95d5d;
    }

    .shop-all .product-content ul li span:before{
      content:'';
      position:absolute;
      border-left:1px solid #d95d5d;
      top:10px;
      z-index: -1;
      height: 92%;
    }

    .shop-all .product-content ul li:last-child span:before{
     content:none;
    }
     .shop-all .product-content ul li:last-child{
      padding-bottom:0
    }

    .shop-all .product-content ul {
      list-style: none;
    }

jquery查询

$('.dot').on('click', function(){
  $(this).toggleClass('filled');
});

Here you need to add class on html as per css and use below jquery在这里,您需要根据 css 在 html 上添加类并在 jquery 下面使用

 $('.dot').on('click', function(){ $('.dot').children('span').removeClass('filled'); $(this).children('span').toggleClass('filled'); });
 .shop-all .product-content ul li { position:relative; font-family: 'Lato'; font-size: 16px; font-weight: bold; padding: 10px 0 10px 0; cursor: pointer;} .shop-all .product-content ul li span { border-radius: 50%; border: 1px solid #d95d5d; padding: 2px 10px; margin-right: 10px; background-color:#fff; } .shop-all .product-content ul li span.filled { background-color: #d95d5d; } .shop-all .product-content ul li span:before{ content:''; position:absolute; border-left:1px solid #d95d5d; top:10px; z-index: -1; height: 92%; } .shop-all .product-content ul li:last-child span:before{ content:none; } .shop-all .product-content ul li:last-child{ padding-bottom:0 } .shop-all .product-content ul { list-style: none; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> <div class="shop-all"> <div class="product-content"> <ul> <li class="dot"><span></span>6"x6" | 599</li> <li class="dot"><span></span>12"x12" | 799</li> <li class="dot"><span></span>12"x18" | 999</li> <li class="dot"><span></span>18"x12" | 799</li> <li class="dot"><span></span>16"x20" | 1,399</li> </ul> </div> </div>

 jQuery("li").click(function() { jQuery(this).toggleClass("active"); jQuery(this).siblings().removeClass("active"); });
 body { margin:0; padding:0;} .container { width: 600px; } .shop-all .product-content ul li { position:relative; font-family: 'Lato'; font-size: 16px; font-weight: bold; padding: 10px 0 10px 0; cursor: pointer; line-height:16px;} .shop-all .product-content ul li span { border-radius: 50%; border: 1px solid #d95d5d; padding: 0 10px; margin-right: 10px; background-color:#fff; } .shop-all .product-content ul li.active span { background-color: #d95d5d; } .shop-all .product-content ul li.active { color: #d95d5d;} .shop-all .product-content ul li span:before{ content:''; position:absolute; border-left:1px solid #d95d5d; top:10px; z-index: -1; height: 92%; } .shop-all .product-content ul li:last-child span:before{ content:none; } .shop-all .product-content ul li:last-child{ padding-bottom:0 } .shop-all .product-content ul { list-style: none; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="container"> <div class="shop-all"> <div class="product-content"> <ul> <li class="dot"><span></span>6"x6" | 599</li> <li class="dot"><span></span>12"x12" | 799</li> <li class="dot"><span></span>12"x18" | 999</li> <li class="dot"><span></span>18"x12" | 799</li> <li class="dot"><span></span>16"x20" | 1,399</li> </ul> </div> </div> </div>

Since you have created filled class for span you have to try the following way.由于您已经为 span 创建了filled类,因此您必须尝试以下方式。 So change所以改变

$('.dot').on('click', function(){
  $(this).toggleClass('filled');
});

To

 $('.dot').on('click', function(){
      $('.dot').find('span').removeClass('filled');
      $(this).find('span').toggleClass('filled');
});

DEMO HERE演示在这里

Try this..尝试这个..

 $('.dot').on('click', function(){ $(this).toggleClass("filled"); $(this).siblings().removeClass("filled"); });
 body { margin:0; padding:0;} .container {width: 600px;} .shop-all .product-content ul li { position:relative; font-family: 'Lato'; font-size: 16px; font-weight: bold; padding: 10px 0 10px 0; cursor: pointer; line-height:16px;} .shop-all .product-content ul li span { border-radius: 50%; border: 1px solid #d95d5d; padding: 0 10px; margin-right: 10px; background-color:#fff; } .shop-all .product-content ul li.filled span { background-color: #d95d5d; } .shop-all .product-content ul li span:before{ content:''; position:absolute; border-left:1px solid #d95d5d; top:10px; z-index: -1; height: 92%; } .shop-all .product-content ul li:last-child span:before{ content:none; } .shop-all .product-content ul li:last-child{ padding-bottom:0 } .shop-all .product-content ul { list-style: none; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="shop-all"> <div class="product-content"> <ul> <li class="dot"><span></span>6"x6" | 599</li> <li class="dot"><span></span>12"x12" | 799</li> <li class="dot"><span></span>12"x18" | 999</li> <li class="dot"><span></span>18"x12" | 799</li> <li class="dot"><span></span>16"x20" | 1,399</li> </ul> </div> </div>

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

相关问题 使用html5单击对应链接时如何用颜色填充圆圈 - How to fill a circle with color when clicked on a correspong link using html5 如何填充颜色/使画布圈可见 - How to fill color/make visible the canvas circle 如何使用jQuery动态更改SVG圆填充颜色的颜色 - How to change the color of an SVG circle fill color using jQuery dynamically 如何编写一个在 CSS 中单击时改变颜色的圆圈 - how to code a circle that changes color when clicked in CSS 如何在html画布中填充颜色圆的某个百分比区域? - how to fill certain percentage area of circle in color in html canvas? 如何创建一个有很多圆圈的表格,以便我可以更改任何圆圈的背景颜色? - How to create a form with many circles so that I could change the background-color of any circle? 画布圈碰撞,如何计算出圈子应该移动到哪里碰撞? - Canvas circle collision, how to work out where circles should move to once collided? 如何用css、javascript围绕一个圆圈创建圆圈? - How to create circles around a circle with css, javascript? 如何近似包含一组圆的圆的半径? - How to approximate the radius of a circle containing a group of circles? HTML5画布 - 绘制线段和圆圈 - 一个圆圈的不同颜色 - HTML5 Canvas - Draw segments and circles - Different color for one circle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM