JQuery enables follow-up ad special effects and jquery Special Effects on the right side of a webpage
Method 1:
<Script type = "text/javascript"> // <! [CDATA [$. 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: "10px"}) ;}else {element.css ({top: scrolls });}} else {element.css ({position: pos, top: top}) ;}}; return $ (this ). each (function () {position ($ (this) ;};/// bind $ ("# float "). smartFloat (); //]> </script>
Method 2:
/* Page intelligence layer floating */jQuery (document ). ready (function ($) {var $ sidebar = $ (". float "), $ window = $ (window), offset = $ sidebar. offset (), topPadding = 20; $ window. scroll (function () {if ($ window. scrollTop ()> offset. top) {$ sidebar. stop (). animate ({marginTop: $ window. scrollTop ()-offset. top + topPadding});} else {$ sidebar. stop (). animate ({marginTop: 0 });}});});
HTML
<Div id = "float" class = "float">
The above two methods can achieve the ad follow-up effect on the right side of the page, hoping to help you.
Articles you may be interested in:
- Js webpage-side scrolling advertisement Effect
- Js writes the mask layer login box and Couplet advertisement and automatically follows the scroll bar to scroll
- Js Implementation of image advertisement instances that follow the mouse and have the function of disabling
- Share the following scrolling code on the right side of the jQuery web page