jquery simple implementation of the page elements when the suspension effect sample _jquery

Source: Internet
Author: User

The example of this article is about the method of the suspension effect of jquery when the page elements are simply implemented. Share to everyone for your reference, specific as follows:

One, JS Code:

<script type= "Text/javascript" >
  $.fn.smartfloat = function () {
    var position = function (element) {
      var top = element.position (). Top, pos = element.css ("position");
      $ (window). Scroll (function () {
        var scrolls = $ (this). ScrollTop ();
        if (Scrolls > top) {
          if window. XMLHttpRequest) {
            element.css ({
              position: "Fixed",
              top:0
            });
          } else {
            element.css ({
              top:scrolls
            });
          }
        else {
          element.css ({
            position:pos,
            top:top
          })
    ;}}; Return $ (a). each (function () {
      position ($ (this));
    });
  Bind
  $ ("#float"). Smartfloat ();
</script>

Second, Html Code:

<div class= "float" id= "float" style= "border:1px solid #e0e0e0; padding:10px; " >
  I was on top of the suspension zone </div>
<br/>
<br/>
<br
/> <br/> <br/ >
<br/>
<br/>
<br/>
<br/> <br/> <br/> <br/>
<br/>
<br/> <br/> <br/> <br/> <br
/ >
<br/>
<br/>
<br/>
<br/> <br/>


More interested readers of jquery-related content can view the site topics: "jquery common Plug-ins and Usage summary", "jquery common Classic Effects Summary", "jquery form operation Tips", "jquery operations JSON data tips," " jquery extension Techniques Summary, jquery drag-and-drop effects and tips summary, jquery table (table) Operation tips Summary, "jquery Ajax Usage Summary", "jquery animation and special effects usage Summary" and "jquery Selector usage Summary"

I hope this article will help you with the jquery program design.

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.