Saturday, 10 October 2015

Jquery fix div position on scroll example

As a UI developer its very necessary to know the how to manage html element in Jquery.  These days many of responsive and fancy design are on top of the template. But sometime we need to fix some html element in order to display some contents or ads on top at constant position, here are few line code hope will help you :-)

Example 1:

     jQuery(function ($) {  
       function fixDivPosition() {  
         var $cache = $('#ads');  
         if ($(window).scrollTop() > 300)  
             'position': 'fixed',  
             'top': '50px'  
             'position': 'relative',  
             'top': 'auto'  


Example 2
 jQuery code

      if ($(this).scrollTop() > 135) {
      } else {
css code

.fixed {position:fixed; top:0; left:0;}