Powered By Blogger

Saturday, December 14, 2013

position fixed using js ,

HEAD tag:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script>
$(function () {
 
  var msie6 = $.browser == 'msie' && $.browser.version < 7;
 
  if (!msie6) {
    var top = $('#right-banner-cakes').offset().top - parseFloat($('#right-banner-cakes').css('margin-top').replace(/auto/, 0));



    $(window).scroll(function (event) {
      var y = $(this).scrollTop();
     
      // whether that's below the form
      if (y >= top) {
        // if so, ad the fixed class
        $('#right-banner-cakes').addClass('fixed');
      } else {
        // otherwise remove it
        $('#right-banner-cakes').removeClass('fixed');
      }


 
    });
  }
});
</script>


BODY tag:

<div id="right-banner-cakes">
        </div>


CSS :
#right-banner-cakes{ width:25%;  height:600px; position: absolute;  }
#right-banner-cakes.fixed { position: fixed; top: 0; }

No comments:

Post a Comment