1

Hello guys I'm working on an online comic right now and am struggeling with following jquery code. Jquery is supposed to change my css code from the #compscreen2 image from "display:none" to "display:block" after the other function happens but it doesn't seem to work and I can't figure out why.... any help please? It seems to work for the other image though.... #compscreen display:none does work. Help!

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;
}
4
  • 1
    Can u post a web inspector screenshot or create a JSBin? Since position: absolute did you check the top position of the element? Maybe its simply off the page... Commented Aug 6, 2016 at 14:12
  • css selector #compscreen2 img but jQuery selector #compscreen2... Commented Aug 6, 2016 at 14:14
  • Can you provide us with the HTML that this code is manipulating? Maybe you could make a pen at Codepen with the HTML, JS and CSS and then we can inspect it. I can't see anything that essentially could cause the code not to work. Commented Aug 6, 2016 at 14:15
  • Have you set the by default property of compscreen2 as display:none? or you loading later by using ajax? Commented Aug 6, 2016 at 14:18

1 Answer 1

2

The css sets display: none for #compscreen2 img, not #compscreen2 itself. You can either make the css something like this:

#compscreen2 {
    display: none;
}

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

or change the js to:

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

You can also use helper functions show and hide to make the code a bit more readable.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you so much!! it worked. Also thanks for the advice :) yayy!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.