欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery實(shí)現(xiàn)全屏滾動(dòng)

 更新時(shí)間:2015年12月28日 08:53:16   作者:jingwhale  
這篇文章主要介紹了jquery實(shí)現(xiàn)全屏滾動(dòng),針對(duì)全屏滾動(dòng)知識(shí)進(jìn)行詳細(xì)闡述,感興趣的小伙伴們可以參考一下

在很多情況下,我們需要頁面的全屏滾動(dòng),尤其是移動(dòng)端。今天簡(jiǎn)要的介紹一下全屏滾動(dòng)的知識(shí)。

一.全屏滾動(dòng)的原理
1.js動(dòng)態(tài)獲取屏幕的高度。

獲取屏幕的高度,設(shè)置每一屏幕的高度。

2.監(jiān)聽mousewheel事件。

監(jiān)聽mousewheel事件,并判斷滾輪的方向,向上或向下滾動(dòng)一屏。

二.jQuery插件fullpages介紹
fullPage.js 是一個(gè)基于 jQuery 的插件,它能夠很方便、很輕松的制作出全屏網(wǎng)站,主要功能有:

  • 支持鼠標(biāo)滾動(dòng)
  • 支持前進(jìn)后退和鍵盤控制
  • 多個(gè)回調(diào)函數(shù)
  • 支持手機(jī)、平板觸摸事件
  • 支持 CSS3 動(dòng)畫
  • 支持窗口縮放
  • 窗口縮放時(shí)自動(dòng)調(diào)整
  • 可設(shè)置滾動(dòng)寬度、背景顏色、滾動(dòng)速度、循環(huán)選項(xiàng)、回調(diào)、文本對(duì)齊方式等

使用方法

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í)顯示的“屏幕”,可以在對(duì)應(yīng)的 section 加上class=”active”,如:

<div class="section active">第三屏</div>

同時(shí),可以在 section 內(nèi)加入 slide(左右滑動(dòng)),如:

<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){}
  });
});

三.動(dòng)手寫全屏滾動(dòng)
這里主要介紹監(jiān)聽mousewheel事件及滾動(dòng)。

由于mousewheel事件的兼容性,引用jquery-mousewheel插件來監(jiān)聽滾輪事件。

通過參數(shù)delta可以獲取鼠標(biāo)滾輪的方向和速度(舊版本需要傳delta參數(shù),新版本不需要,直接用event?。?。如果delta的值是負(fù)的,那么滾輪就是向下滾動(dòng),正的就是向上。

// 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)全屏滾動(dòng)(上下,左右),也可以使用jquery-mousewheel定制不同高度的全屏滾動(dòng)。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。

相關(guān)文章

最新評(píng)論