jquery - ScrollTo() method not working -


i trying use scrollto() making div become fixed after touches top on scrolling. here full html script added:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8" />         <title>untitled document</title>         <script type="text/javascript" src="jquery-1.9.1.min.js"></script>         <style>             .topnav{                 width:100%;                  background-color:#444;                  color:#eee;                  padding:10px;                  position:relative;             }         </style>         <script>             $(window).scroll(function(){                  if($('body').scrollto('.topnav', {offsettop : '0'})){                      $(this).css('position','fixed');                     $(this).css('top','0');                  } else {                      $(this).css('position','relative');                 }             });         </script>     <head>     <body>         <br/>         <br/>         <br/>         <br/>         <br/>sdsf         <br/><br/><br/><br/><br/><br/><br/><br/><br/>          <div class="topnav">topnav</div>          <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>         <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>dfgv<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>      </body> </html> 

but not working @ all. logic thjat if div scrolls top @ 0 position, position should change relative fixed, fixes @ top after that. please tell did wrong.

after little investigation, clear you're missing add scrollto() plugin.

<script type='text/javascript' src='http://flesler.com/jquery/scrollto/js/jquery.scrollto-min.js' />  

add code.

check in jsfiddle


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -