久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

stellar.js - 為垂直滾動網(wǎng)站配置偏移量/對齊元素

stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網(wǎng)站配置偏移量/對齊元素?)
本文介紹了stellar.js - 為垂直滾動網(wǎng)站配置偏移量/對齊元素?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我發(fā)現(xiàn)并正在嘗試使用一個名為 stellar.js 的插件.主要是為網(wǎng)站創(chuàng)建視差效果,但是,我不追求這種效果——我追求的是它提供的另一種效果:

I have found, and am trying to use, a plugin called stellar.js. Primarily it is for creating a parallax effect for websites, but, I am not after this effect - I am after the other effect it offers:

Stellar.js 最強(qiáng)大的功能是它對齊元素的方式.

Stellar.js' most powerful feature is the way it aligns elements.

所有元素都將返回到它們的原始位置offset parent 與屏幕邊緣相交——加或減你自己的可選偏移量.

All elements will return to their original positioning when their offset parent meets the edge of the screen—plus or minus your own optional offset.

偏移定位示例:http://markdalgleish.com/projects/stellar.js/#show-offsets .當(dāng)您滾動 div 時,它會捕捉/重新對齊到瀏覽器的邊緣.我正試圖讓它適用于垂直網(wǎng)站.

An example of the offset positioning: http://markdalgleish.com/projects/stellar.js/#show-offsets . When you scroll over a div it snaps/realigns to the edge of the browser. I am trying to get this to work for a vertical website.

由于我對 Javascript 和 jQuery 的新手了解,我運(yùn)氣不佳.我認(rèn)為這只是將水平交換為垂直的情況.

I am not having much luck - due to my novice knowledge of Javascript and jQuery. I thought it would just be a case of swapping around the horizontals to verticals.

有沒有人玩過這個插件,或者在類似的場景中使用過它,并得到任何提示?

Has anyone played with this plugin before, or used it for a similar scenario, and got any tips?

包含所有代碼的 jsFiddle:http://jsfiddle.net/2SH2T/

The jsFiddle with all the code: http://jsfiddle.net/2SH2T/

以及 Javascript 代碼:

And the Javascript code:

var STELLARJS = {
    init: function() {
        var self = this;
        $(function(){
            self.$sections = $('div.section').each(function(index){
                $(this).data('sectionIndex', index);
            });

            self.highlightSyntax();
            self.handleEvents();

            self.debugOffsets.init();
            self.debugOffsetParents.init();

            self.initParallax();
        });
    },
    initParallax: function() {
        var isHomePage = $('body').hasClass('home'),
            $main = $('div.main');

        if (isHomePage) {
            $main.height($main.height() + $(window).height() - 1000);
        }

        if ($.browser.msie) {
            $('body').removeAttr('data-stellar-background-ratio').append('<div class="ie-bg" />');
        }

        $(window).stellar({
            horizontalOffset: !isHomePage,
            verticalScrolling: 40
        });
    },
    highlightSyntax: function() {
        $('pre').addClass('prettyprint');
        if (window.prettyPrint !== undefined) prettyPrint();
    },
    handleEvents: function() {
        var self = this,
            //Debounce function from Underscore.js
            debounce = function(func, wait) {
                var timeout;
                return function() {
                    var context = this, args = arguments;
                    var later = function() {
                        timeout = null;
                        func.apply(context, args);
                    };
                    clearTimeout(timeout);
                    timeout = setTimeout(later, wait);
                }
            },
            handleScroll = function() {
                var scrollTop = $(window).scrollTop(),
                    sectionIndex = Math.round((scrollTop - 40) / self.$sections.first().outerHeight()),
                    $activeSection = self.$sections.eq(sectionIndex);

                if ($activeSection.length === 0) {
                    $activeSection = self.$sections.last();
                }

                if ($activeSection.length === 0) return;

                $(window).unbind('scroll.stellarsite');

                if (scrollLeft === 0) {
                    $(window).unbind('scroll.stellarsite').bind('scroll.stellarsite', debounce(handleScroll, 500));
                } else {
                    $('html,body').animate({
                        scrollLeft: $activeSection.offset().left - 40
                    }, 600, 'easeInOutExpo', function() {
                        setTimeout(function(){
                            $(window).unbind('scroll.stellarsite').bind('scroll.stellarsite', debounce(handleScroll, 500));
                        }, 10);
                    });
                }

                $(window).bind('mousewheel', function(){
                    $('html,body').stop(true, true);
                });

                $(document).bind('keydown', function(e){
                    var key = e.which;

                    if (key === 37 || key === 39) {
                        $('html,body').stop(true, true);
                    }
                });
            };

        if (window.location.href.indexOf('#show-offset-parents-default') === -1) {
            $(window).bind('scroll.stellarsite', debounce(handleScroll, 500));
        }
    },
    debugOffsets: {
        init: function() {
            this.$debug = $('#debugOffsets');

            if (window.location.href.indexOf('#show-offsets') > -1) {
                this.show();
            }
        },
        show: function() {
            this.$debug.fadeIn();
            $('body').addClass('debugOffsets');
            $('h2').append('<div class="debug-h2-label">Offset Parent (All parallax elements align when this meets the offsets)</div>');
        },
        hide: function() {
            this.debug.fadeOut;
            $('body').removeClass('debugOffsets');
        }
    },
    debugOffsetParents: {
        init: function() {
            this.$debug = $('#debugOffsets');

            if (window.location.href.indexOf('#show-offset-parents-default') > -1) {
                this.removeOffsetParents();
            }

            if (window.location.href.indexOf('#show-offset-parents') > -1) {
                this.show();
            }            
        },
        show: function() {
            this.$debug.fadeIn();

            $('body').addClass('debugOffsetParents');
            $('h2').append('<div class="debug-h2-label">New Offset Parent (All parallax elements align when this meets the offsets)</div>');
            $('h2').each(function(){
                $(this).find('div.constellation:last').append('<div class="debug-constellation-label">Default Offset Parents</div>');
            });
            $('body').addClass('debug');
        },
        removeOffsetParents: function() {
            $('body').addClass('debugOffsetParentsDefault');
            $('h2[data-stellar-offset-parent]').removeAttr('data-stellar-offset-parent');
        }
    }
};

STELLARJS.init();

推薦答案

我修改了原代碼,得到了和stellarjs.com一樣的效果.相反,它是垂直的:)

I modified the original code and came up with exact effect like in stellarjs.com. Instead it's vertical :)

看看:http://jsfiddle.net/E4uVD/38/

這篇關(guān)于stellar.js - 為垂直滾動網(wǎng)站配置偏移量/對齊元素?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創(chuàng)建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設(shè)置值/標(biāo)簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進(jìn)行單元測試?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當(dāng)文本框獲得焦點(diǎn)時選擇所有內(nèi)容)
Is it possible to force jQuery.jScrollPane to always show a vertical scroll-bar?(是否可以強(qiáng)制 jQuery.jScrollPane 始終顯示垂直滾動條?)
主站蜘蛛池模板: 99视频在线 | 999久久久 | 成人国产在线视频 | 亚洲美女一区 | 欧美日韩在线视频一区 | 日韩精品在线免费观看 | 国产精品国产三级国产aⅴ中文 | 一区二区三区免费观看 | 99精品久久 | 久久一区二区视频 | 另类一区 | 国产传媒毛片精品视频第一次 | 国产精品免费一区二区三区四区 | 成人国产免费视频 | 99国产精品久久久久久久 | 国产一区二区精品在线观看 | 高清一区二区三区 | 欧美a级成人淫片免费看 | www.788.com色淫免费 | 激情欧美一区二区三区中文字幕 | 成人在线电影在线观看 | 国产精品一区二区三区在线播放 | 日韩精品久久久久 | 国产精品成人一区二区 | av大片在线观看 | 毛片在线看看 | 九九久久久 | 天天射影院 | 激情久久网| 天天干天天插 | 国产精品一区二区视频 | 黄网站在线观看 | 日日草夜夜草 | 黑人精品| 亚洲国产欧美国产综合一区 | 成人国产精品一级毛片视频毛片 | 久久久久久国产精品免费免费 | 久久aⅴ乱码一区二区三区 亚洲国产成人精品久久久国产成人一区 | 91精品国产综合久久久久久 | 亚州中文 | www.欧美.com|