0

I am trying to add some style elements to my jquery code.

My objective is to be able to position a box absolutely after the person has scrolled down the screen after 200px.

The box reduces in size after a 200px scroll but i want to have the ability to position the box where i want.

Here is my code.

Can some one guide me on where I am going wrong.

Fiddle

  $( window ).scroll(function() {
     if($(window).scrollTop() > 200){
       $('#profile-pic-bg').css({'width': '50'});
        $("#profile-pic-bg").css({ position: "absolute", top: "20", left:"5" });
     }else{
         $('#profile-pic-bg').css({'width': '145'});
     }

});
user2965875
  • 681
  • 3
  • 11
  • 19

2 Answers2

4

Remove the quotes from the top and left property values, or they wont work:

$("#profile-pic-bg").css({ position: "absolute", top: 20, left: 5 });
David Hellsing
  • 97,234
  • 40
  • 163
  • 203
1

Try with this

$( window ).scroll(function() {
     if($(window).scrollTop() > 200){

        $("#profile-pic-bg").css({ 
            "position": "absolute", 
            "top": "20px", 
            "left":"5px" ,
            "width":'50px'
        });
     }else{
         $('#profile-pic-bg').css({'width': '145px'});
     }

});

DEMO

Sridhar R
  • 19,414
  • 6
  • 36
  • 35