Jquery implements layer div auto-Floating Top instance

Source: Internet
Author: User

The Floating Top effect is not always like this, but when we scroll to the specified position, the specified DIV layer will automatically hover the top. Next I will introduce the implementation process.

Directly use the following code

The Code is as follows: Copy code

<Script src = "http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"> </script>
 
<Script src = "/blog/js/scroll. js"> </script>
 
<Div class = "y_bds" style = "clear: both;">
Pay attention to two points: one is style clear: both, and the other produces class = y_bds
</Div>

This code is inserted into the template directory loop-single.php
(If your blog already has the jquery. js file, delete the first line of code)

Scroll. js is a separate file for Xiaosheng, the content of which is as follows:

The Code is as follows: Copy code
$ (Document). ready (function (){
Var headHeight = 200; // there is actually a better method for this height. Users can manually adjust the settings as needed.
 
Var nav = $ (". y_bds ");
$ (Window). scroll (function (){
 
If ($ (this). scrollTop ()> headHeight ){
Nav. addClass ("navFix ");
}
Else {
Nav. removeClass ("navFix ");
}
})
})

Style.css under the Template

The Code is as follows: Copy code

/* Add css 2013-4-2 */
. NavFix {background: # FFF; position: fixed; left: 140px; top: 0px; width: 600px; _ position: absolute; top: expression (offsetParent. scrollTop) + 0); z-index: 2 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.