简体   繁体   English

使用Tabs html css和jquery

[英]Using Tabs html css and jquery

I have this html fragment which represent a tabbed interface, I have been looking around how to enable the tab selection on click but no use, I even programmed it manually using javascript, it worked, but i believe this is not the professional way to do it, there must be some jquery solution. 我有这个html片段代表一个标签界面,我一直在寻找如何启用单击但没有用的选项卡选择,我甚至使用javascript手动编程,它工作,但我相信这不是专业的方式做它,必须有一些jquery解决方案。 I am posting below the html code fragment 我发布在html代码片段下面

<div class="services">
    <div class="tabs">  

    <!--Top Tabs panel-->

    <ul class="ui-tabs-nav" id="services">
        <li class="ui-state-default ui-tabs-selected ui-state-active"><a href="#ui-tabs-currency"><span>العملات</span></a></li>
        <li class="ui-state-default"><a href="#ui-tabs-weather"><span>حالة الطفس</span></a></li>
    </ul>                                         

    <!--Bottom Tabs panel-->                        

    <div id="ui-tabs-currency" class="ui-tabs-panel ui-widget-content">
        <div class="pnl">
        sdfdsfsf
        </div>                                          
    </div>

    <div id="ui-tabs-weather" class="ui-tabs-panel ui-widget-content ui-tabs-hide">
        <div class="pnl">
        hhhhhhhhhhhhh
        </div>              
    </div>

    <div class="more"></div>                

    </div> <!-- End of tabs -->                
</div> <!-- End of services -->

jQuery is JavaScript, there is no "professional" way of doing this. jQuery是JavaScript,没有“专业”的方式来做到这一点。 There is only the method that best suits the need. 只有最适合需要的方法。 If your method works, it works. 如果你的方法有效,那就有效。 If you want to see how it can be made better, consider posting the code on Code Review . 如果您想了解如何做得更好,请考虑在Code Review上发布代码。

Take a look at jQuery UI Tabs if you want to see a jQuery way of doing this. 如果你想看到一个jQuery方法,看一下jQuery UI Tabs Although, judging from your class names, you might already be using this... which leads me to wonder what you're trying to ask. 虽然,从你的班级名称来看,你可能已经在使用这个...这让我想知道你想要问什么。

You can use jQuery-ui 你可以使用jQuery-ui

HTML HTML

<div class="services">
    <div class="tabs">
        <ul>
            <li><a href="#tabs-currency">العملات</a></li>
            <li><a href="#tabs-weather">حالة الطفس</a></li>
        </ul>

        <div id="tabs-currency"><p>sdfdsfsf</p></div>

        <div id="tabs-weather"><p>hhhhhhhhhhhhh</p></div>

    </div>
</div>

JS JS

$(function() {
    $( ".tabs" ).tabs();
});​

See the working demo here and reference Here . 请参阅此处的工作演示参考此处

如果您正在寻找jQuery解决方案,那么您应该使用jQuery UI选项卡

I assume you specifically want that code to work? 我假设您特别希望该代码有效吗? if not this works really nicely. 如果不是这个真的很好。 just drop your table in where it says (and probably you'll want to remove the 把你的桌子放在它所说的位置(可能你会想要删除它

tags there now 现在标记

    .tabs {
    max-width: 90%;
    float: none;
    list-style: none;
    padding: 0;
    margin: 75px auto;
    border-bottom: 4px solid #ccc;
}
.tabs:after {
    content: '';
    display: table;
    clear: both;
}
.tabs input[type=radio] {
    display:none;
}
.tabs label {
    display: block;
    float: left;
    width: 33.3333%;
    color: #ccc;
    font-size: 30px;
    font-weight: normal;
    text-decoration: none;
    text-align: center;
    line-height: 2;
    cursor: pointer;
    box-shadow: inset 0 4px #ccc;
    border-bottom: 4px solid #ccc;
    -webkit-transition: all 0.5s; /* Safari 3.1 to 6.0 */
    transition: all 0.5s;
}
.tabs label span {
    display: none;
}
.tabs label i {
    padding: 5px;
    margin-right: 0;
}
.tabs label:hover {
    color: #3498db;
    box-shadow: inset 0 4px #3498db;
    border-bottom: 4px solid #3498db;
}
.tab-content {
    display: none;
    width: 100%;
    float: left;
    padding: 15px;
    box-sizing: border-box;
    background-color:#ffffff;
}

.tab-content * {
    -webkit-animation: scale 0.7s ease-in-out;
    -moz-animation: scale 0.7s ease-in-out;
    animation: scale 0.7s ease-in-out;
}
@keyframes scale {
  0% {
    transform: scale(0.9);
    opacity: 0;
    }
  50% {
    transform: scale(1.01);
    opacity: 0.5;
    }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.tabs [id^="tab"]:checked + label {
    background: #FFF;
    box-shadow: inset 0 4px #3498db;
    border-bottom: 4px solid #3498db;
    color: #3498db;
}
#tab1:checked ~ #tab-content1,
#tab2:checked ~ #tab-content2,
#tab3:checked ~ #tab-content3 {
    display: block;
}

@media (min-width: 768px) {
    .tabs i {
        padding: 5px;
        margin-right: 10px;
    }
    .tabs label span {
        display: inline-block;
    }
    .tabs {
    max-width: 750px;
    margin: 50px auto;
    }
}

CSS CSS

  .tabs { max-width: 90%; float: none; list-style: none; padding: 0; margin: 75px auto; border-bottom: 4px solid #ccc; } .tabs:after { content: ''; display: table; clear: both; } .tabs input[type=radio] { display:none; } .tabs label { display: block; float: left; width: 33.3333%; color: #ccc; font-size: 30px; font-weight: normal; text-decoration: none; text-align: center; line-height: 2; cursor: pointer; box-shadow: inset 0 4px #ccc; border-bottom: 4px solid #ccc; -webkit-transition: all 0.5s; /* Safari 3.1 to 6.0 */ transition: all 0.5s; } .tabs label span { display: none; } .tabs label i { padding: 5px; margin-right: 0; } .tabs label:hover { color: #3498db; box-shadow: inset 0 4px #3498db; border-bottom: 4px solid #3498db; } .tab-content { display: none; width: 100%; float: left; padding: 15px; box-sizing: border-box; background-color:#ffffff; } .tab-content * { -webkit-animation: scale 0.7s ease-in-out; -moz-animation: scale 0.7s ease-in-out; animation: scale 0.7s ease-in-out; } @keyframes scale { 0% { transform: scale(0.9); opacity: 0; } 50% { transform: scale(1.01); opacity: 0.5; } 100% { transform: scale(1); opacity: 1; } } .tabs [id^="tab"]:checked + label { background: #FFF; box-shadow: inset 0 4px #3498db; border-bottom: 4px solid #3498db; color: #3498db; } #tab1:checked ~ #tab-content1, #tab2:checked ~ #tab-content2, #tab3:checked ~ #tab-content3 { display: block; } @media (min-width: 768px) { .tabs i { padding: 5px; margin-right: 10px; } .tabs label span { display: inline-block; } .tabs { max-width: 750px; margin: 50px auto; } } 

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

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