3

よし、パララックス Web サイトを Wordpress に移植しようとしていますが、これまでのところ頭痛の種しかありません。最終的にデスクトップ ブラウザではすべて動作するようになりましたが、モバイル ブラウザではさまざまな問題が発生しています。私のスクリプトのこの部分 (Stellar と iScroll を使用) をモバイル ブラウザーで表示しないようにする方法を誰かに教えてもらえれば、あるいはさらに良いことに、なぜ私がこれほど多くの問題を抱えているのかわかるかもしれません。いずれにせよ、jQuery/Javascript は私にとってかなりなじみのないものなので、アドバイスをいただければ非常にありがたいです。ティア!

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

            //self.handleEvents();

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

            self.initParallax();
        });
    },

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

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

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


        if (isMobileWebkit) {

            iScrollInstance = new iScroll('scroller');

              jQuery('#wrapper').stellar({
                parallaxBackgrounds:false,
                scrollProperty: 'transform',
                positionProperty: 'customPositionTransform',
                hideDistantElements: false,
                horizontalScrolling: false,
                verticalOffset: verticalOffset
              });

              console.log('isMobileWebkit'+iScrollInstance);
        } else {
            console.log('is not MobileWebkit');
             jQuery(window).stellar({
                /*
                    scrollProperty: 'scroll',
                    positionProperty: 'position',
                    horizontalScrolling: true,
                    verticalScrolling: true,
                    horizontalOffset: 0,
                    verticalOffset: 0,
                    responsive: false,
                    parallaxBackgrounds: true,
                    parallaxElements: true,
                    hideDistantElements: true,
                    hideElement: function($elem) { $elem.hide(); },
                    showElement: function($elem) { $elem.show(); }
                */
                positionProperty: 'customPositionTransform',
                horizontalScrolling: false,
                verticalOffset: verticalOffset,
                horizontalOffset: 0,
                verticalScrolling: true,
                hideDistantElements: false,

            });
        }


    },

    handleEvents: function() {
        var self = this,
            //Debounce function from Underscore.js
            debounce = function(func, wait) {
                console.log('debounce');
                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() {
                console.log('handleScroll');
                var scrollLeft = $(window).scrollLeft(),
                    sectionIndex = Math.round((scrollLeft - 40) / self.$sections.first().outerWidth()),
                    $activeSection = self.$sections.eq(sectionIndex);

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

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

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

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

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

                jQuery(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) {
            jQuery(window).bind('scroll.stellarsite', debounce(handleScroll, 500));
        }
    },
    debugOffsets: {
        init: function() {
            this.$debug = jQuery('#debugOffsets');

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

3 に答える 3

1
function isMobile() {
  return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}

if (!isMobile()) {
 //if its not mobile then start script otherwise turn it off (just place the script    under this comment
}
于 2014-06-12T05:03:16.700 に答える