JQUERY CSS "display" "block" 即使 "display" "none" 有效....

JQUERY CSS "display" "block" does not work even though "display" "none" does work....

大家好,我现在正在制作在线漫画,正在努力处理以下 jquery 代码。 Jquery 应该在其他功能发生后将我的 css 代码从 #compscreen2 图像从 "display:none" 更改为 "display:block" 但它似乎不起作用而且我不能'不知道为什么....请帮忙吗? 它似乎适用于其他图像...... #compscreen display:none 确实有效。求助!

JS :

$(document).ready(function () {

//function for automated top scrolling
$(window).on('scroll', function(e){
  scrollPosY();

  if ($('#panel11').visible(true) && scrolled == 0) {
  $('html, body').stop().animate( { scrollTop: $('.scrollpanel').offset().top }, 500 )
  scrolled = 1;
  $("div.wrap2").remove();
  $("#compscreen2").css("display","block");
  $("#compscreen").css("display", "none"); 
  }
});

$window = $(window);


});

CSS :

#compscreen2 img{
    width: 60%;
    padding-left: 20%;
    position: absolute;
    display: none;
}

css 为 #compscreen2 img 设置 display: none,而不是 #compscreen2 本身。您可以使 css 像这样:

#compscreen2 {
    display: none;
}

#compscreen2 img {
    width: 60%;
    padding-left: 20%;
    position: absolute;
}

或者把js改成:

$("#compscreen2 img").css("display","block");

您还可以使用辅助函数 show and hide 使代码更具可读性。