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
  • 701
  • 5
  • 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
  • 106,495
  • 44
  • 176
  • 212
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
  • 20,190
  • 6
  • 38
  • 35