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.