css活动类不适用于Tabs

时间:2017-12-07 07:45:51

标签: jquery css html5

请你帮帮我吗?

css活动类不适用于Tabs

演示:http://dev.ktimes.co/was20378/tab/index-nw2.html

CSS

.filter-button
{
        padding: 6px 20px;
    font-size: 18px;
    border: 1px solid #fd0009;
    border-radius: 20px;
    text-align: center;
    color: #fd0009;
    margin-bottom: 30px;

}
.filter-button:hover, .filter-button.active
{
    font-size: 18px;
    border: 1px solid #fd0009;
   border-radius: 20px;
    text-align: center;
    color: #ffffff;
    background-color: #fd0009;

}
.btn-default.filter-button.active {
    background-color: #fd0009 !important;
    color: #FFF !important;
}

3 个答案:

答案 0 :(得分:1)

.active未添加到.filter-button课程,请尝试检查脚本中的问题

答案 1 :(得分:0)

试试这样:

        $(document).ready(function () {

        $(".filter-button").click(function () {
            var value = $(this).attr('data-filter');

            if (value == "all") {
                $('.filter').show('1000');
            }
            else {

                $(".filter").not('.' + value).hide('3000');
                $('.filter').filter('.' + value).show('3000');

                }

               $(".filter-button").removeClass("active");


               $(this).addClass("active");
        });
    });

答案 2 :(得分:0)

你的jquery有一个简单的问题,你在click函数之外写了条件,这就是为什么没有添加活动类,现在已经解决了使用snippet检查运行这个工作片段

$(document).ready(function(){

    $(".filter-button").click(function(){
        var value = $(this).attr('data-filter');
        
        if(value == "all")
        {
            //$('.filter').removeClass('hidden');
            $('.filter').show('1000');
        }
        else
        {
//            $('.filter[filter-item="'+value+'"]').removeClass('hidden');
//            $(".filter").not('.filter[filter-item="'+value+'"]').addClass('hidden');
            $(".filter").not('.'+value).hide('3000');
            $('.filter').filter('.'+value).show('3000');
            
        }
		$(".filter-button").removeClass('active');
		$(this).addClass("active");
    });
    
    
	

});
a, a:focus, a:active, * {
				outline:0 !important;
			}
	
			
.gallery-title
{
    font-size: 36px;
    color: #42B32F;
    text-align: center;
    font-weight: 500;
    margin-bottom: 70px;
}
.gallery-title:after {
    content: "";
    position: absolute;
    width: 7.5%;
    left: 46.5%;
    height: 45px;
    border-bottom: 1px solid #5e5e5e;
}
.filter-button
{
	    padding: 6px 20px;
    font-size: 18px;
    border: 1px solid #fd0009;
   	border-radius: 20px;
    text-align: center;
    color: #fd0009;
    margin-bottom: 30px;

}
.filter-button:hover, .filter-button.active
{
    font-size: 18px;
    border: 1px solid #fd0009;
   border-radius: 20px;
    text-align: center;
    color: #ffffff;
    background-color: #fd0009;

}
.btn-default.filter-button.active {
    background-color: #fd0009 !important;
    color: #FFF !important;
}
	
						

.port-image
{
    width: 100%;
}

.gallery_product
{
    margin-bottom: 30px;
}

.gallery_heading_pan {
	width: 96%;
	text-align: center;
	float: left;
	padding: 15px 2%;
	font-size: 20px;
	font-weight: 500;
	color: #333;
	}			
			
			
.image_gly {
  opacity: 1;
  display: block;
  width: 100%;
  height: auto;
  transition: .5s ease;
  backface-visibility: hidden;
}

.middle {
  transition: .5s ease;
  opacity: 0;
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%)
}

.gallery_nf:hover .image_gly {
  opacity: 0.3;
}

.gallery_nf:hover .middle {
  opacity: 1;
}

.text {
  border-radius: 10px;
  background-color: #fd0009;
  color: white;
  font-size: 16px;
  padding: 16px 32px;
}	
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
        <div class="row">
        <div class="gallery col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <h1 class=""></h1>
        </div>

        <div align="center">
            <button class="btn btn-default filter-button" data-filter="all">All</button>
            <button class="btn btn-default filter-button active" data-filter="hdpe">HDPE Pipes</button>
            <button class="btn btn-default filter-button" data-filter="sprinkle">Sprinkle Pipes</button>
            <button class="btn btn-default filter-button" data-filter="spray">Spray Nozzle</button>
            <button class="btn btn-default filter-button" data-filter="irrigation">Irrigation Pipes</button>
        </div>
        <br>



            <div class="gallery_product col-lg-3 col-md-3 col-sm-4 col-xs-6 filter hdpe" style="display: block;"> <a href="http://dev.ktimes.co/was20378/tab/index-nw2.html#"><img src="./Bootstrap_files/saved_resource" class="img-responsive"></a>
            		<div class="gallery_heading_pan">Heading Text here</div>
            </div>

           
            <div class="gallery_product col-lg-3 col-md-3 col-sm-4 col-xs-6 filter hdpe" style="display: block;"> <a href="http://dev.ktimes.co/was20378/tab/index-nw2.html#"><img src="./Bootstrap_files/saved_resource" class="img-responsive"></a>
            		<div class="gallery_heading_pan">Heading Text here</div>
            </div>

            <div class="gallery_product col-lg-3 col-md-3 col-sm-4 col-xs-6 filter hdpe" style="display: block;"> <a href="http://dev.ktimes.co/was20378/tab/index-nw2.html#"><img src="./Bootstrap_files/saved_resource" class="img-responsive"></a>
            		<div class="gallery_heading_pan">Heading Text here</div>
            </div>

            <div class="gallery_product col-lg-3 col-md-3 col-sm-4 col-xs-6 filter irrigation" style="display: none;"> 
            <a href="http://dev.ktimes.co/was20378/tab/index-nw2.html#"><img src="./Bootstrap_files/saved_resource" class="img-responsive"></a>
            		<div class="gallery_heading_pan">Heading Text here</div>
            </div>

            <div class="gallery_product col-lg-3 col-md-3 col-sm-4 col-xs-6 filter spray" style="display: none;">
                <img src="./Bootstrap_files/saved_resource" class="img-responsive">
                <div class="gallery_heading_pan">Heading Text here</div>
            </div>

            <div class="gallery_product col-lg-3 col-md-3 col-sm-4 col-xs-6 filter irrigation" style="display: none;">
                <img src="./Bootstrap_files/saved_resource" class="img-responsive">
                <div class="gallery_heading_pan">Heading Text here</div>
            </div>

            <div class="gallery_product col-lg-3 col-md-3 col-sm-4 col-xs-6 filter spray" style="display: none;">
                <img src="./Bootstrap_files/saved_resource" class="img-responsive">
                <div class="gallery_heading_pan">Heading Text here</div>
            </div>

            <div class="gallery_product col-lg-3 col-md-3 col-sm-4 col-xs-6 filter irrigation" style="display: none;">
                <img src="./Bootstrap_files/saved_resource" class="img-responsive">
                <div class="gallery_heading_pan">Heading Text here</div>
            </div>

            <div class="gallery_product col-lg-3 col-md-3 col-sm-4 col-xs-6 filter irrigation" style="display: none;">
                <img src="./Bootstrap_files/saved_resource" class="img-responsive">
                <div class="gallery_heading_pan">Heading Text here</div>
            </div>

            <div class="gallery_product col-lg-3 col-md-3 col-sm-4 col-xs-6 filter hdpe" style="display: block;">
                <img src="./Bootstrap_files/saved_resource" class="img-responsive">
                <div class="gallery_heading_pan">Heading Text here</div>
            </div>

            <div class="gallery_product col-lg-3 col-md-3 col-sm-4 col-xs-6 filter spray" style="display: none;">
                <img src="./Bootstrap_files/saved_resource" class="img-responsive">
                <div class="gallery_heading_pan">Heading Text here</div>
            </div>

            <div class="gallery_product col-lg-3 col-md-3 col-sm-4 col-xs-6 filter sprinkle" style="display: none;">
                <img src="./Bootstrap_files/saved_resource" class="img-responsive">
                <div class="gallery_heading_pan">Heading Text here</div>
            </div>
        </div>
    </div>
  
   
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>