I need to add custom css to jquery tabs when it is selected, how?

后端 未结 3 1124
我寻月下人不归
我寻月下人不归 2021-01-28 15:23

I need to modify the css of .ui-state-active , .ui-widget-content .ui-state-active to the following:

.ui-state-active , .ui-widget-content .ui-state-active {
            


        
相关标签:
3条回答
  • 2021-01-28 15:52

    You could put the code in the select event of the tab control

    $( "#tabs" ).tabs({
       select: function(event, ui) { 
         //ui.item has the current object for you.
       }
    });
    

    http://docs.jquery.com/UI/Tabs#event-select

    0 讨论(0)
  • 2021-01-28 15:53

    If I don't misunderstand your question, you could simply do as following:

    $('#tabs .tab-menu li a').click(function() {
        $('#tabs .tab-menu li').css('background-image', 'url("images/original-bg.png")');
        $(this).parent().css('background-image', 'url("images/tab-over.png")'; 
    });
    
    0 讨论(0)
  • 2021-01-28 16:00

    WHOA! Way over-extending things here!

    OK, First of all, jQuery is great, but it has already done the work. To do what you are trying to achieve, you don't need ANY JavaScript of any kind. Use simple CSS.

    Watch:

    /*  FYI: The following CSS selector can also be used to make changes 
        via JavaScript/jQuery to Currently selected tab.
        I have a blog post about that I'll list at the end of my answer */
    .ui-tabs-selected {
        background-image: url('images/tab-over.png') !important;
    } /* This will change the background of the 
         currently selected li element acting as the tab */
    
    /*  If you would like to change the background or something of current panel,
        you would access it with the following CSS selector */
    .ui-tabs-panel:not(.ui-tabs-hide) {
        background-image: url('images/tab-over.png') !important;
    } /* This will change the background of the 
         currently selected div element acting as the panel */
    

    As for that link I promised earlier, this blog post goes into much more depth about ez access to currently selected tabs "outside" of the "tabs events".

    0 讨论(0)
提交回复
热议问题