0

I'm having this little function which sets a div to position:fixed after a link is clicked.

$(window).load(function(){
    $('#linktofreeze').click(function() {
        var ftop = $('#fixedbox').offset().top - $(window).scrollTop();
        var fleft = $('#fixedbox').offset().left;
        $('#fixedbox').css({position: 'fixed', left: fleft + 'px', top: ftop + 'px'});
    });
});

What I'm trying to achieve now, is to make the whole thing backwards: When a second link is clicked, the div's position shouldn't be 'fixed' anymore.

What is the best way to do this? Is there a way to delete/remove this function 'onClick' again?

To make it more clear, I uploaded the files on jsFiddle: http://jsfiddle.net/hZX5h/72/

Would be great if anyone could help. Thanks!

Andrew Whitaker
  • 119,029
  • 30
  • 276
  • 297
Kev89
  • 97
  • 8

3 Answers3

2

Reset its position to relative

$("#linktounfreeze").click(function() {
  $('#fixedbox').css({position: 'relative'});  
  return false;
});

fiddle: http://jsfiddle.net/vVbGy/1/

Elvis D'Souza
  • 2,093
  • 21
  • 29
0

Is it what you want? (Add this in the end of your js code):

$('#linktounfreeze').click(function () {
  $('#fixedbox').css({
    position: 'relative'
  });
return null;
});
Ben
  • 449
  • 2
  • 4
  • 20
0

You can use the unbind method to achieve this:

$('#linktofreeze').attr('onclick','').unbind('click');

Better method in jQuery 1.7+

$('#linktofreeze').off('click');
Icarus
  • 60,193
  • 14
  • 91
  • 110