简体   繁体   English

更改单击jQuery时的引导指示器

[英]Change Bootstrap Indicators on click jQuery

Sorry I don't have enough internet post to post an image. 抱歉,我没有足够的互联网帖子来发布图片。 I want to be able to change each image to its sprite counterpart. 我希望能够将每个图像更改为其对应的精灵。 There are three list items. 有三个列表项。 I can't for the life of me figure out how to change them, because they all have two classes that need to be changed. 我一辈子都想不出如何更改它们,因为它们都有两个需要更改的类。

All have sprite images. 都有精灵图片。 This is what I've tried. 这就是我尝试过的。

$(function(){
$('#carousel-indicatorsForms li').on('click', function(){
    if($('#takeout').hasClass('active')){
        $(this).removeClass('buttonsSm-food_1sm');
        $(this).addClass('buttonsSm-food_2sm');
    } else if ($('#groceries').hasClass('active')) {
        $('#takeout').removeClass('buttonsSm-food_2sm');
        $('#takeout').addClass('buttonsSm-food_1sm');           
    }
});

}); });

Here's the HTML: 这是HTML:

  <ol id="carousel-indicatorsForms" class="carousel-indicators">
<li id="takeout" data-target="#carousel-example-generic" data-slide-to="0" class="buttonsSm-sprite buttonsSm-food_1sm carouselButton active"></li>
<li id="groceries" data-target="#carousel-example-generic" data-slide-to="1" class="buttonsSm-sprite buttonsSm-grocery_1sm carouselButton"></li>
<li id="custom" data-target="#carousel-example-generic" data-slide-to="2" class="buttonsSm-sprite buttonsSm-other_1sm carouselButton"></li></ol>

What I really want is to click on one and it changes the sprite to the "more blue" version of the image. 我真正想要的是单击一个,它将精灵更改为图像的“更蓝”版本。

The Sprites' classes are .buttonsSm-other_1sm and .buttonsSm-other_2sm, white and blue respectively. Sprites的类分别是.buttonsSm-other_1sm和.buttonsSm-other_2sm,白色和蓝色。

Thought this "visual" might help. 认为这种“视觉效果”可能会有所帮助。 So for instance: first one clicked [ XOO ] second one clicked [ OXO ] last one clicked [ OOX ] , with X being the active image, and O being the opposite. 因此,例如:第一个单击[XOO],第二个单击[OXO],最后一个单击[OOX],其中X是活动图像,O是相反的图像。 Sorry but I still can't post images. 抱歉,我仍然无法发布图片。

I'm over complicating this I'm sure. 我敢肯定,这已经使问题复杂化了。 Can someone help? 有人可以帮忙吗?

i'm not entirely sure what you're trying to do in your click logic.... because you're not switching the class, you're only doing one continual action (which is to remove a class and add a class) and not toggling it. 我不完全确定您要在点击逻辑中尝试做什么...。因为您没有在切换班级,所以您只是在做一个连续动作(即删除班级并添加班级)而不要切换它。 So instead you can have the default sprite on the element and what you can do is say... add a single class to change out the sprite since it MUST have at least one type of sprite and then say, if this solution doesn't meet your needs, could you clarify a little the why of your current logic? 因此,相反,您可以在元素上使用默认的子画面,并且可以说......添加单个类以更改子画面,因为它必须至少具有一种类型的子画面,然后说,如果此解决方案没有满足您的需求,您能否澄清一下当前逻辑的原因?

$("#takeout").toggleClass("blueSprite"); 

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

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