jquery實(shí)現(xiàn)全屏滾動
在很多情況下,我們需要頁面的全屏滾動,尤其是移動端。今天簡要的介紹一下全屏滾動的知識。
一.全屏滾動的原理
1.js動態(tài)獲取屏幕的高度。
獲取屏幕的高度,設(shè)置每一屏幕的高度。
2.監(jiān)聽mousewheel事件。
監(jiān)聽mousewheel事件,并判斷滾輪的方向,向上或向下滾動一屏。
二.jQuery插件fullpages介紹
fullPage.js 是一個(gè)基于 jQuery 的插件,它能夠很方便、很輕松的制作出全屏網(wǎng)站,主要功能有:
- 支持鼠標(biāo)滾動
- 支持前進(jìn)后退和鍵盤控制
- 多個(gè)回調(diào)函數(shù)
- 支持手機(jī)、平板觸摸事件
- 支持 CSS3 動畫
- 支持窗口縮放
- 窗口縮放時(shí)自動調(diào)整
- 可設(shè)置滾動寬度、背景顏色、滾動速度、循環(huán)選項(xiàng)、回調(diào)、文本對齊方式等
使用方法
1、引入文件
<link rel="stylesheet" href="css/jquery.fullPage.css"> <script src="js/jquery.min.js"></script> <script src="js/jquery.fullPage.js"></script>
2、HTML
<div id="dowebok">
<div class="section">
<h3>第一屏</h3>
</div>
<div class="section">
<h3>第二屏</h3>
</div>
<div class="section">
<h3>第三屏</h3>
</div>
<div class="section">
<h3>第四屏</h3>
</div>
</div>
每個(gè) section 代表一屏,默認(rèn)顯示“第一屏”,如果要指定加載頁面時(shí)顯示的“屏幕”,可以在對應(yīng)的 section 加上class=”active”,如:
<div class="section active">第三屏</div>
同時(shí),可以在 section 內(nèi)加入 slide(左右滑動),如:
<div id="fullpages">
<div class="section">第一屏</div>
<div class="section">第二屏</div>
<div class="section">
<div class="slide">第三屏的第一屏</div>
<div class="slide">第三屏的第二屏</div>
<div class="slide">第三屏的第三屏</div>
<div class="slide">第三屏的第四屏</div>
</div>
<div class="section">第四屏</div>
</div>
3、JavaScript
$(function(){
$('#fullpages').fullpage();
});
可以進(jìn)行跟多的配置:
$(document).ready(function() {
$('#fullpages').fullpage({
//Navigation
menu: '#menu',
lockAnchors: false,
anchors:['firstPage', 'secondPage'],
navigation: false,
navigationPosition: 'right',
navigationTooltips: ['firstSlide', 'secondSlide'],
showActiveTooltip: false,
slidesNavigation: true,
slidesNavPosition: 'bottom',
//Scrolling
css3: true,
scrollingSpeed: 700,
autoScrolling: true,
fitToSection: true,
fitToSectionDelay: 1000,
scrollBar: false,
easing: 'easeInOutCubic',
easingcss3: 'ease',
loopBottom: false,
loopTop: false,
loopHorizontal: true,
continuousVertical: false,
normalScrollElements: '#element1, .element2',
scrollOverflow: false,
touchSensitivity: 15,
normalScrollElementTouchThreshold: 5,
//Accessibility
keyboardScrolling: true,
animateAnchor: true,
recordHistory: true,
//Design
controlArrows: true,
verticalCentered: true,
resize : false,
sectionsColor : ['#ccc', '#fff'],
paddingTop: '3em',
paddingBottom: '10px',
fixedElements: '#header, .footer',
responsiveWidth: 0,
responsiveHeight: 0,
//Custom selectors
sectionSelector: '.section',
slideSelector: '.slide',
//events
onLeave: function(index, nextIndex, direction){},
afterLoad: function(anchorLink, index){},
afterRender: function(){},
afterResize: function(){},
afterSlideLoad: function(anchorLink, index, slideAnchor, slideIndex){},
onSlideLeave: function(anchorLink, index, slideIndex, direction, nextSlideIndex){}
});
});
三.動手寫全屏滾動
這里主要介紹監(jiān)聽mousewheel事件及滾動。
由于mousewheel事件的兼容性,引用jquery-mousewheel插件來監(jiān)聽滾輪事件。
通過參數(shù)delta可以獲取鼠標(biāo)滾輪的方向和速度(舊版本需要傳delta參數(shù),新版本不需要,直接用event?。?。如果delta的值是負(fù)的,那么滾輪就是向下滾動,正的就是向上。
// using on
$('#my_elem').on('mousewheel', function(event) {
console.log(event.deltaX, event.deltaY, event.deltaFactor);
});
// using the event helper
$('#my_elem').mousewheel(function(event) {
console.log(event.deltaX, event.deltaY, event.deltaFactor);
});
可以根據(jù)需求使用fullpages實(shí)現(xiàn)全屏滾動(上下,左右),也可以使用jquery-mousewheel定制不同高度的全屏滾動。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助。
相關(guān)文章
jQuery學(xué)習(xí)筆記 操作jQuery對象 文檔處理
HTML文檔的層次關(guān)系是樹型的,每個(gè)標(biāo)簽可視為樹的各個(gè)節(jié)點(diǎn)。若操作jQuery對象,使得HTML文檔的結(jié)構(gòu)發(fā)生了改變,就叫做文檔處理2012-09-09
跟著JQuery API學(xué)Jquery 之二 屬性
在選擇器的API學(xué)習(xí)中,走馬觀花的把選擇器過了一遍,但是選擇歸選擇,選擇出來了沒干什么事,也沒有什么用嘛2010-04-04
jquery select 設(shè)置默認(rèn)選中的示例代碼
本篇文章主要是對jquery select 設(shè)置默認(rèn)選中的示例代碼進(jìn)行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-02-02
jQuery實(shí)現(xiàn)點(diǎn)擊水紋波動動畫
今天要為大家紹一款由jquery實(shí)現(xiàn)的鼠標(biāo)單擊出現(xiàn)水波特效。用鼠標(biāo)點(diǎn)擊頁面,你可以看到頁面不斷出面水波紋效果。然后水波紋漸漸消失。效果非常不錯(cuò)2016-04-04
模仿jQuery each函數(shù)的鏈?zhǔn)秸{(diào)用
模仿jQuery each函數(shù)的鏈?zhǔn)秸{(diào)用實(shí)現(xiàn)代碼。2009-07-07
jQuery實(shí)現(xiàn)動畫效果circle實(shí)例
這篇文章主要介紹了jQuery實(shí)現(xiàn)動畫效果circle的方法,涉及jquery鼠標(biāo)事件及頁面動畫操作相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08
jquery checkbox,radio是否選中的判斷代碼
jquery checkbox,radio是否選中的判斷代碼,需要的朋友可以參考下。2010-03-03
jQuery插件HighCharts繪制2D帶Label的折線圖效果示例【附demo源碼下載】
這篇文章主要介紹了jQuery插件HighCharts繪制2D帶Label的折線圖效果,結(jié)合實(shí)例形式分析了jQuery圖形繪制插件HighCharts實(shí)現(xiàn)折線圖效果的具體操作步驟與相關(guān)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-03-03

