Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 切换回幻灯片时是否更改背景色?_Jquery - Fatal编程技术网

Jquery 切换回幻灯片时是否更改背景色?

Jquery 切换回幻灯片时是否更改背景色?,jquery,Jquery,当我单击一个元素以滑动切换其他一些元素时,我也会更改我单击的元素的背景色,以指示这是选定的元素。但是,当我单击并滑回元素时,如何删除背景色 $(".c756:eq(0)").click(function(){ $(".c756:eq(0)").css('background-color','yellow'); $("#wrapper_datorpaket").slideToggle(); }); 我将设置一个“highlight”类,并使用toggleClass,将开关设置为包

当我单击一个元素以滑动切换其他一些元素时,我也会更改我单击的元素的背景色,以指示这是选定的元素。但是,当我单击并滑回元素时,如何删除背景色

$(".c756:eq(0)").click(function(){
    $(".c756:eq(0)").css('background-color','yellow');
    $("#wrapper_datorpaket").slideToggle();
});
我将设置一个“highlight”类,并使用
toggleClass
,将开关设置为包装器元素的可见性

.highlight {
    background-color: yellow
}

$(".c756:eq(0)").click(function(){
    var that = this;
    $("#wrapper_datorpaket").slideToggle(function() {

        // this doesn't have to be in the callback
        // unless you want the highlight added/removed
        // on completion of the animation
        $(that).toggleClass("highlight", $(this).is(":visible"));
    });
});
您可以使用:


您好,我希望您能告诉我如何编辑我的脚本,使高光变化是即时的,而不是在动画结束时,我想不出这一点<代码>$(function(){$('.contents').hide();$('body').on('click','.product',function(){var that=this;$(this).find('.contents').slideToggle('slow',function(){$(this).toggleClass('highlight',$(this).is('visible”);})
$('.c756:eq(0)').toggle(function () {
    $(this).css('background-color', 'yellow');
}, function () {
    $(this).css('background-color', 'transparent');
}).click(function () {
    $('#wrapper_datorpaket').slideToggle();
});