jQuery¼¼Êõ

headroom.js²å¼þʹÓ÷½·¨

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2015-09-20 08:29 ÎÒÒªÆÀÂÛ( )

±¾ÎÄÖ÷Òª½²½âheadroom.js²å¼þµÄʹÓ÷½·¨£¬Óë´ó¼Ò·ÖÏí¡£

[ÕªÒª]±¾ÎÄÖ÷Òª½²½âheadroom.js²å¼þµÄʹÓ÷½·¨£¬Óë´ó¼Ò·ÖÏí¡£


1.ʲôÊÇheadroom.js£¿


2.¹¤×÷Ô­Àí

ͨ¹ý¸ÐӦĿ±êÔªËز»Í¬µÄ3ÖÖ״̬£¨Ô­Ê¼£¬Ï¹ö£¬ÉϹö£©£¬ÎªÄ¿±êÔªËظü¸ÄÏàÓ¦µÄclass£¬Í¨¹ýÏàÓ¦µÄclassµÄcssÑùʽµÄ±ä»¯µÃµ½ËùÒªµÄЧ¹û¡£


3.ÈçºÎʹÓÃ

£¨ÒÔϵÄÀý×ÓÊÇ»ùÓÚbootstrap¿ò¼ÜºÍjquery²å¼þµÄ£¬ÔÚbootstrap¿ò¼ÜÏ¿ÉÒÔ¿ìËÙд³öµ¼º½À¸navbar£¬È»ºóÒÔjquery²å¼þ·½Ê½¶Ôµ¼º½À¸navbarµ÷ÓÃheadroom()¡££©

Ê×ÏÈÐèÒªÒýÓÃheadroom.jsºÍjQuery.headroom.js¡£½«ÒÔϵĴúÂë¼ÓÈëµ½ÄãµÄ´úÂëÖС£headroom.js×÷Ó㺸ÐÓ¦ÔªËز»Í¬µÄ״̬Ϊ֮¸ü¸ÄÏàÓ¦µÄclass¡£jQuery.headroom.js×÷ÓãºÌṩjquery²å¼þ·½Ê½ºÍData-API·½Ê½µ÷ÓÃheadrooom()¡£

<script type="text/javascript" src="https://rawgithub.com/WickyNilliams/headroom.js/master/dist/headroom.js"></script> <script type="text/javascript" src="https://rawgithub.com/WickyNilliams/headroom.js/master/src/jQuery.headroom.js"></script> ÒòΪheadroom()º¯Êý´«ÈëµÄ²ÎÊýoption¶ÔÏóµÄĬÈÏÖµÈçÏ¡£



{ // ÔÚÔªËØûÓй̶¨Ö®Ç°£¬´¹Ö±·½ÏòµÄÆ«ÒÆÁ¿£¨ÒÔpxΪµ¥Î»£© offset : 0, // scroll tolerance in px before state changes tolerance : 0, // ¶ÔÓÚÿ¸ö״̬¶¼¿ÉÒÔ×Ô¶¨Òåcss classes classes : { // µ±ÔªËسõʼ»¯ºóËùÉèÖõÄclass initial : "headroom", // ÏòÉϹö¶¯Ê±ÉèÖõÄclass pinned : "headroom--pinned", // ÏòϹö¶¯Ê±ËùÉèÖõÄclass unpinned : "headroom--unpinned" } }


ÓÉ´Ë¿É֪ԭʼµÄ״̬¶ÔÓ¦µÄclassÊÇheadroom£¬Ï¹öʱµÄclassÊÇheadroom--pinned£¬ÉϹöʱµÄclassÊÇheadroom--unpinned¡£ËùÒÔÎÒÃÇÒªÌí¼ÓÏÂÃæµÄÑùʽ£¬Í¨¹ýcssµÄtrasitionÊôÐÔ´ïµ½±ä»»Ð§¹û¡£


<style type="text/css"> .headroom {position: fixed;top: 0;left: 0;right: 0;transition: all .2s ease-in-out;} .headroom--unpinned {top: -100px;} .headroom--pinned {top: 0;} </style> Ö®ºóÌí¼ÓÏÂÃæµÄjs´úÂ룬ʹÓÃjquery²å¼þµÄ·½Ê½µ÷Óá£".navbar-fixed-top"Ö»ÊÇÓÃÀ´»ñÈ¡µ¼º½À¸navbar£¬Ò²¿ÉÒÔÓÃÆäËûÑ¡ÔñÆ÷À´»ñÈ¡navbarÄ¿±êÔªËØ



<script type="text/javascript"> $(".navbar-fixed-top").headroom(); </script>

×öÍêÁËÉÏÊö²½Ö裬ÀíÂÛÉÏÄã¾Í¿ÉÒÔ¿´µ½headroomµÄЧ¹ûÁË£¬Èç¹ûûÓгɹ¦¿ÉÄÜÊÇÒÔϵÄÔ­Òò£º

  • jsµÄÒýÓÃ˳Ðò´íÎó£¬ÒòΪһЩjsÒªÓõ½ÆäËûjs²ÅÄÜÔËÐеģ¬ËùÒÔ±ØÐë·ÅÔÚÆäËûµÄjsÖ®ºó¡£ÀýÈç <script type="text/javascript"> $(".navbar-fixed-top").headroom(); </script> ±ØÐë·ÅÔÚheadroom.jsºÍjQuery.headroom.jsÖ®ºó£¬¶øheadroom.jsºÍjQuery.headroom.js±ØÐë·ÅÔÚjQuery.jsÖ®ºó¡£

  • ½«$(".navbar-fixed-top").headroom(); ·ÅÔÚÖ÷Ìåhtml´úÂë֮ǰ£¬Èç·ÅÔÚ<head></head>ÖУ¬ÒòΪÔÚÖ÷Ìåhtml´úÂë֮ǰ£¬navbarÔªËØ»¹Ã»¼ÓÔؾ͵÷ÓÃÁËheadroom()£¬ËùÒÔÎÞЧ¡£Ó¦¸ÃÓÃÒÔÏ´úÂëÌæ»»Ö®£¬±íʾµÈÎĵµ¼ÓÔØÍê±ÏÔÙµ÷Óᣠ<script type="text/javascript"> $("doucument").ready(fuction(){ $(".navbar-fixed-top").headroom(); }); </script>
  • ÉÏÊöµÄЧ¹ûÖ»ÊÇͨ¹ýcss×Ô´øµÄtrasitionÊôÐÔÀ´ÊµÏÖЧ¹û£¬±È½Ïµ¥µ÷¡£²»¹ý¿ÉÒÔ½áºÏanimate.cssʵÏÖ¸ü¶àµÄƯÁÁµÄÏûʧºÍ³öÏÖµÄЧ¹û¡££¨²é¿´Ð§¹û£©

    animate.cssʹÓô¿cssΪ¸÷ÖÖÔªËØʵÏÖ²»Í¬µÄ¶¯»­Ð§¹û£¬Ã¿Ò»ÖÖclass¶ÔÓ¦Ò»ÖÖ¶¯»­Ð§¹û£¬ËùÒÔ½«animate.cssÒýÈë´úÂëºóheadroom()¿ÉÒÔÖ±½ÓʹÓÃÒѾ­Ð´ºÃµÄclass¡££¨animate.cssÏÂÔØ£©

    ÎÒ»ùÓÚbootstrapºÍjqueryдµÃÀý×Ó¡£



    <!DOCTYPE html> <html> <head> <title>Bootstrap 101 Template</title> <meta content="width=device-width, initial-scale=1.0"> <!-- Bootstrap --> <link href="http://cdn.bootcss.com/twitter-bootstrap/3.0.3/css/bootstrap.min.css"> <link href="I:/webpage/animate/animate.css"> <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="http://cdn.bootcss.com/html5shiv/3.7.0/html5shiv.min.js"></script> <script src="http://cdn.bootcss.com/respond.js/1.3.0/respond.min.js"></script> <![endif]--> <style type="text/css"> .headroom {position: fixed;top: 0;left: 0;right: 0;transition: all .2s ease-in-out;} .headroom--unpinned {top: -100px;} .headroom--pinned {top: 0;} </style> <style type="text/css"> .scrollspy-example { height: 1200px; overflow: auto; position: relative; } </style> </head> <body> <!-- ҳü´óÆÁÏÔʾ --> <div> <div> <h1>Hello, world!</h1> <p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p> <p><a role="button">Learn more </a></p> </div> </div> <div> <!-- µ¼º½À¸ --> <nav role="navigation"> <div> <a href="#">w3school</a> </div> <div> <ul> <li><a href="#php">PHP</a></li> <li><a href="#js">JS</a></li> <li> <a href="#" data-toggle="dropdown">database<b></b></a> <ul> <li><a href="#mysql">MySQL</a></li> <li><a href="#pgsql">PostgreSQL</a></li> <li><a href="#mgdb">MogoDB</a></li> </ul> </li> </ul> </div> </nav> <!-- Ö÷ÌåÄÚÈÝ--> <div data-spy="scroll" data-target="#example" data-offset="0"> <h4>PHP</h4> <p>PHP, an acronym for Hypertext Preprocessor, is a widely-used open source general-purpose scripting language. It is an HTML embedded scripting language and is especially suited for web development. The basic syntax of PHP is similar to C, Java, and Perl, and is easy to learn. PHP is used for creating interactive and dynamic web pages quickly, but you can do much more with PHP. </p> <h4>JS</h4> <p> JavaScript is a cross-platform, object-oriented scripting language developed by Netscape. JavaScript was created by Netscape programmer Brendan Eich. It was first released under the name of LiveScript as part of Netscape Navigator 2.0 in September 1995. It was renamed JavaScript on December 4, 1995. As JavaScript works on the client side, It is mostly used for client-side web development. </p> <h4>MySQL</h4> <p> MySQL tutorial of w3cschool is a comprhensive tutorial to learn MySQL. We have hundreds of examples covered, often with PHP code. This helps you to learn how to create PHP-MySQL based web applications. </p> <h4>PostgreSQL</h4> <p> In 1986 the Defense Advanced Research Projects Agency (DARPA), the Army Research Office (ARO), the National Science Foundation (NSF), and ESL, Inc sponsored Berkeley POSTGRES Project which was led by Michael Stonebrakessr. In 1987 the first demo version of the project is released. In June 1989, Version 1 was released to some external users. Version 2 and 3 were released in 1990 and 1991. Version 3 had support for multiple storage managers, an query executor was improved, rule system was rewritten. After that, POSTGRES has been started to be implemented in various research and development projects. For example, in late 1992, POSTGRES became the primary data manager for the Sequoia 2000 scientific computing project4. User community around the project also has been started increasing; by 1993, it was doubled. </p> <h4>MongoDB</h4> <p> The term NoSQL was coined by Carlo Strozzi in the year 1998. He used this term to name his Open Source, Light Weight, DataBase which did not have an SQL interface.In the early 2009, when last.fm wanted to organize an event on open-source distributed databases, Eric Evans, a Rackspace employee, reused the term to refer databases which are non-relational, distributed, and does not conform to atomicity, consistency, isolation, durability - four obvious features of traditional relational database systems. </p> <p> After reading the largest third party online MySQL tutorial by w3cschool, you will be able to install, manage and develop PHP-MySQL web applications by your own. We have a comprehensive, SQL TUTORIAL, which will help you to understand how to prepare queries to fetch data against various conditions. </p> </div> </div> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="http://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="http://cdn.bootcss.com/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script> <script type="text/javascript" src="https://rawgithub.com/WickyNilliams/headroom.js/master/dist/headroom.js"></script> <script type="text/javascript" src="https://rawgithub.com/WickyNilliams/headroom.js/master/src/jQuery.headroom.js"></script> <script type="text/javascript"> $(".navbar-fixed-top").headroom(); </script> </body> </html>

    headroom.jsÔ´ÂëÏÂÔØ£º

    ¡¡

    1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

    Ïà¹ØÎÄÕÂ
    ÍøÓѵãÆÀ
    ¼