久久天天躁狠狠躁夜夜免费观看,精品国产粉嫩内射白浆内射双马尾,久久国产欧美日韩精品,久久久久久性高,激情欧美成人久久综合

Bootstrap Affix 插件 高級(jí)用法詳細(xì)講解

JSON 2016-11-03 16:40:52 6347

Bootstrap 附加導(dǎo)航(Affix)插件

附加導(dǎo)航(Affix)插件允許某個(gè) <div> 固定在頁(yè)面的某個(gè)位置。您也可以在打開或關(guān)閉使用該插件之間進(jìn)行切換。一個(gè)常見的例子是社交圖標(biāo)。它們將在某個(gè)位置開始,但當(dāng)頁(yè)面點(diǎn)擊某個(gè)標(biāo)記,該 <div> 會(huì)鎖定在某個(gè)位置,不會(huì)隨著頁(yè)面其他部分一起滾動(dòng)。

Demo:http://suancuo.cn/json/

這個(gè)Demo鏈接你上下滑動(dòng)的時(shí)候。注意一個(gè)細(xì)節(jié),到了最下面碰到footer的時(shí)候,自動(dòng)又往上頂,這個(gè)是需要用 function 來解決。先把代碼貼一下:

HTML代碼

<div class="bc-sidebar affix-top" id="myAffix">
	<ul class="nav nav-list nav-tabs nav-stacked bs-docs-sidenav dropdown" style="width: 255px;">
	  <li class="active"><a href="http://suancuo.cn/json/" title="JSON 教程">JSON 教程</a></li>
	  <li class=""><a href="http://suancuo.cn/json/json_intro.html" title="JSON 簡(jiǎn)介">JSON 簡(jiǎn)介</a></li>
	  <li class=""><a href="http://suancuo.cn/json/json_syntax.html" title="JSON 語(yǔ)法">JSON 語(yǔ)法</a></li>
	  <li class=""><a href="http://suancuo.cn/json/json_eval.html" title="JSON 使用">JSON 使用</a></li>
	  <li class=""><a href="http://suancuo.cn/in.html" title="10分鐘掌握J(rèn)SON">10分鐘掌握J(rèn)SON</a></li>
	  <li class=""><a href="http://suancuo.cn/blog/25.html" title="JSON.stringify 函數(shù)">JSON.stringify 函數(shù)</a></li>
	  <li class=""><a href="http://suancuo.cn/blog/100.html" title="Java中json-lib操作">Java中json-lib操作</a></li>
	  <li class=""><a href="http://suancuo.cn/blog/20.html" title="Java中json-lib操作">Json-lib jar包下載</a></li>
	  <li class=""><a href="http://suancuo.cn/blog/46.html" title="Http JSON代替Webservice">Http JSON代替Webservice</a></li>
	  <li class=""><a href="http://suancuo.cn/blog/1.html" title="JSON 和XML比較">JSON 和XML比較</a></li>
	  <li class=""><a href="http://suancuo.cn/blog/121.html" title="JSONP 的工作原理,JSONP Demo講解">JSONP Demo講解</a></li>
	</ul>
</div>

注意div 上要增加class="affix-top"  ,并且最好定義一個(gè)id 。

Javascript 代碼

$('#myAffix').affix({
	  offset: {
		top: 202,
		bottom: function () {
		  //不超過footer 高度 + 165px 的位置
		  return (this.bottom =  $('.footer').height() +165 );
		}
	  }
});

top:是頁(yè)面頂部到菜單的高度,其實(shí)也就是滾動(dòng)條滾動(dòng)到這個(gè)位置的時(shí)候,開始跟著頂部走。

bottom:同理是滾動(dòng)到一定程度,距離頁(yè)面最底部需要空余多少空間出來。(px)

下面來一張圖說明。

然后就可以了,這是高級(jí)用法,但是我發(fā)現(xiàn)了一個(gè)BUG,還是只有我這里有問題?

到底部后條件bottom 滿足后,元素(div)添加了一個(gè)屬性position: relative; 和動(dòng)態(tài)的 top 值,來固定高度。但是再往上滑動(dòng)滾動(dòng)條的時(shí)候,這個(gè)屬性沒有刪除position: relative;導(dǎo)致再一次滾動(dòng)失效了,因?yàn)楣潭ㄗ∵@個(gè)元素(div)了。這個(gè)時(shí)候我把代碼改成這樣了。下面看看。

$('#myAffix').affix({
	  offset: {
		top: function () {
		   //當(dāng)往上滾動(dòng)的時(shí)候,判斷一下有沒有這個(gè)屬性,如果有就刪除style。
		   if($('#myAffix').v('style') == 'position: relative;'){
			   $('#myAffix').removeAttr('style');
		   }
		   return 202;
		},
		bottom: function () {
		  //不超過footer 高度 + 165px 的位置
		  return (this.bottom = $('.footer').height() +165 );
		}
	  }
});

解決了這個(gè)Bug 。 如果有更好的辦法告知我。

Data配置方式

<div class="bc-sidebar affix-top" data-spy="affix" data-offset-top="200" data-offset-bottom="256">
	<ul class="nav nav-list nav-tabs nav-stacked bs-docs-sidenav dropdown" style="width: 255px;">
	  <li class="active"><a href="http://suancuo.cn/json/" title="JSON 教程">JSON 教程</a></li>
	  <li class=""><a href="http://suancuo.cn/json/json_intro.html" title="JSON 簡(jiǎn)介">JSON 簡(jiǎn)介</a></li>
	  <li class=""><a href="http://suancuo.cn/json/json_syntax.html" title="JSON 語(yǔ)法">JSON 語(yǔ)法</a></li>
	  <li class=""><a href="http://suancuo.cn/json/json_eval.html" title="JSON 使用">JSON 使用</a></li>
	  <li class=""><a href="http://suancuo.cn/in.html" title="10分鐘掌握J(rèn)SON">10分鐘掌握J(rèn)SON</a></li>
	  <li class=""><a href="http://suancuo.cn/blog/25.html" title="JSON.stringify 函數(shù)">JSON.stringify 函數(shù)</a></li>
	  <li class=""><a href="http://suancuo.cn/blog/100.html" title="Java中json-lib操作">Java中json-lib操作</a></li>
	  <li class=""><a href="http://suancuo.cn/blog/20.html" title="Java中json-lib操作">Json-lib jar包下載</a></li>
	  <li class=""><a href="http://suancuo.cn/blog/46.html" title="Http JSON代替Webservice">Http JSON代替Webservice</a></li>
	  <li class=""><a href="http://suancuo.cn/blog/1.html" title="JSON 和XML比較">JSON 和XML比較</a></li>
	  <li class=""><a href="http://suancuo.cn/blog/121.html" title="JSONP 的工作原理,JSONP Demo講解">JSONP Demo講解</a></li>
	</ul>
</div>

這樣的方式就是不能計(jì)算,值是死的。

data-spy="affix" data-offset-top="200" data-offset-bottom="256"

實(shí)現(xiàn)Affix

在上面兩種使用附加導(dǎo)航(Affix)插件的方式中,您都必須通過  CSS   定位內(nèi)容。附加導(dǎo)航(Affix)插件在三種 class 之間切換,每種 class 都呈現(xiàn)了特定的狀態(tài): .affix .affix-top .affix-bottom 。請(qǐng)按照下面的步驟,來為這三種狀態(tài)設(shè)置您自己的 CSS(不依賴此插件)。

  1. 在開始時(shí),插件添加 .affix-top  來指示元素在它的最頂端位置。這個(gè)時(shí)候不需要任何的 CSS 定位。

  2. 當(dāng)滾動(dòng)經(jīng)過添加了附加導(dǎo)航(Affix)的元素時(shí),應(yīng)觸發(fā)實(shí)際的附加導(dǎo)航(Affix)。此時(shí) .affix 會(huì)替代 .affix-top ,同時(shí)設(shè)置position: fixed; (由 Bootstrap 的 CSS 代碼提供)。

  3. 如果定義了底部偏移,當(dāng)滾動(dòng)到達(dá)該位置時(shí),應(yīng)把 .affix 替換為.affix-bottom 。由于偏移是可選的,假如設(shè)置了該偏移,則要求同時(shí)設(shè)置適當(dāng)?shù)?nbsp;CSS。在這種情況下,請(qǐng)?jiān)诒匾臅r(shí)候添加position: absolute; 。

 屬性名稱  類型/默認(rèn)值  Data屬性名稱  詳細(xì)描述
 

offset

 

number | function | object

默認(rèn)值:10

 

data-offset

 

當(dāng)瀏覽器動(dòng)位置時(shí),距離頂部的偏移像素。如果設(shè)置了一個(gè)數(shù)字,則該偏移量的值將被應(yīng)用在頂部和底部。如果設(shè)置了一個(gè)對(duì)象偏移,則其值形如 offset: { top: 10 } 或 offset: { top: 10, bottom: 5 }。如果需要?jiǎng)討B(tài)計(jì)算偏移,請(qǐng)使用函數(shù)。


本站就是采用Bootstarp建設(shè)。


版權(quán)所屬:SO JSON在線解析

原文地址:http://suancuo.cn/blog/185.html

轉(zhuǎn)載時(shí)必須以鏈接形式注明原始出處及本聲明。

本文主題:

如果本文對(duì)你有幫助,那么請(qǐng)你贊助我,讓我更有激情的寫下去,幫助更多的人。

關(guān)于作者
一個(gè)低調(diào)而悶騷的男人。
相關(guān)文章
Linux 安裝 Redis 詳細(xì)步驟講解
Maven的Mirror和Repository 的詳細(xì)講解
PHP用戶定義函數(shù)詳細(xì)講解
TCP 和 UDP協(xié)議詳細(xì)講解,優(yōu)缺點(diǎn)分析講解
document.domain解決跨域問題,詳細(xì)講解。
PHP用戶定義函數(shù)詳細(xì)講解
Myecilpse,Eclipse安裝Freemarker插件【附件】
wangEditor 添加高亮 highlightJS 插件
SEO 之 SpringMVC redirect 301,301和302區(qū)別詳細(xì)講解
Plupload 上傳詳細(xì)講解,Plupload 多實(shí)例上傳,Plupload多個(gè)上傳按鈕
最新文章
計(jì)算機(jī)網(wǎng)絡(luò)的相關(guān)內(nèi)容 540
SOJSON V6 JavaScript 解密技巧與分析 6017
微信客服人工電話95068:如何快速解封微信賬號(hào)(2025最新指南) 12036
Java Http請(qǐng)求,HttpURLConnection HTTP請(qǐng)求丟失頭信息,Head信息丟失解決方案 5056
實(shí)用API合集分享:教你輕松獲取IP地址的API合集 8859
Linux I/O重定向 6723
Ruby 循環(huán) - while、for、until、break、redo 和 retry 3990
Node.js:全局對(duì)象 3612
如何使用終端檢查L(zhǎng)inux上的內(nèi)存使用情況 3779
JavaScript對(duì)象詳細(xì)剖析 3280
最熱文章
免費(fèi)天氣API,天氣JSON API,不限次數(shù)獲取十五天的天氣預(yù)報(bào) 745858
最新MyEclipse8.5注冊(cè)碼,有效期到2020年 (已經(jīng)更新) 703281
蘋果電腦Mac怎么恢復(fù)出廠系統(tǒng)?蘋果系統(tǒng)怎么重裝系統(tǒng)? 678460
Jackson 時(shí)間格式化,時(shí)間注解 @JsonFormat 用法、時(shí)差問題說明 561961
我為什么要選擇RabbitMQ ,RabbitMQ簡(jiǎn)介,各種MQ選型對(duì)比 511842
Elasticsearch教程(四) elasticsearch head 插件安裝和使用 483725
Jackson 美化輸出JSON,優(yōu)雅的輸出JSON數(shù)據(jù),格式化輸出JSON數(shù)據(jù)... ... 299571
Java 信任所有SSL證書,HTTPS請(qǐng)求拋錯(cuò),忽略證書請(qǐng)求完美解決 246685
Elasticsearch教程(一),全程直播(小白級(jí)別) 232162
227542
支付掃碼

所有贊助/開支都講公開明細(xì),用于網(wǎng)站維護(hù):贊助名單查看

查看我的收藏

正在加載... ...