好的,所以我正在尝试将视差网站移植到 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');
}
}
};