JQuery實(shí)現(xiàn)網(wǎng)頁(yè)右側(cè)隨動(dòng)廣告特效
更新時(shí)間:2016年01月17日 09:45:21 投稿:hebedich
本文給大家分享的是2則使用jquery實(shí)現(xiàn)網(wǎng)頁(yè)右側(cè)隨動(dòng)廣告特效的代碼,非常的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。
方法一:
<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));
});
};
//綁定
$("#float").smartFloat();
// ]]></script>
方法二:
/*頁(yè)面智能層浮動(dòng)*/
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"> <h3>推薦</h3> 廣告代碼 </div>
以上2種方法都可以實(shí)現(xiàn)頁(yè)面右側(cè)的隨動(dòng)廣告特效,希望對(duì)大家能夠有所幫助。
相關(guān)文章
jquery寫個(gè)checkbox——類似郵箱全選功能
最近在學(xué)習(xí)jquery,今天抽空用jquery寫個(gè)checkbox——類似郵箱全選功能,感興趣的你可以參考下哈,希望可以幫助到你2013-03-03
jQuery實(shí)現(xiàn)左右滑動(dòng)的toggle方法
下面小編就為大家分享一篇jQuery實(shí)現(xiàn)左右滑動(dòng)的toggle方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-03-03
jquery 操作兩個(gè)select實(shí)現(xiàn)值之間的互相傳遞
本篇文章主要是對(duì)jquery操作兩個(gè)select實(shí)現(xiàn)值之間的互相傳遞進(jìn)行了詳細(xì)的介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2014-03-03
jQuery 打造動(dòng)態(tài)下滑菜單實(shí)現(xiàn)說明
本教程將分步講解如何使用JQuery和CSS打造一個(gè)炫酷動(dòng)感菜單。2010-04-04
jQuery 重復(fù)加載錯(cuò)誤以及修復(fù)方法
本文主要記錄了在項(xiàng)目中遇到j(luò)Query重復(fù)加載導(dǎo)致依賴jQuery的js全部失效然后一步步分析,得出最終解決方案的全部過程,主要是記錄下來,提醒自己以后不要再犯相同錯(cuò)誤。2014-12-12
jquery插件unobtrusive實(shí)現(xiàn)片段式加載
本文給大家分享的是使用jquery插件unobtrusive實(shí)現(xiàn)片段式加載,效果非常不錯(cuò),有需要的小伙伴可以參考下。2015-06-06

