jquery page Right ads follow scrolling code sharing _jquery

Source: Internet
Author: User

Both methods are shared with you, hoping to inspire us to learn from each other.

Method One:

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

Method Two:

/* page Smart layer floating/ 
jQuery (document). Ready (function ($) { 
  var $sidebar = $ (". Float"), 
  $window = $ (window), 
  offset = $sidebar. Offset (), 
  toppadding =; 
  $window. Scroll (function () { 
    if ($window. scrolltop () > Offset.top) { 
      $sidebar. Stop (). Animate ({ 
        MarginTop: $window. scrolltop ()-Offset.top + toppadding 
      }); 
    else { 
      $sidebar. Stop (). Animate ({ 
        margintop:0 
      }); 
}}); <div id= "float" class= "float" > 
 
 

The above is the jquery page on the right side of the ads follow the scrolling, copy wordpress Right ads Follow the scroll, I hope to help you learn.

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.