我正在使用此代码将“显示”类添加到我的图像中,这样当有人向下滚动时,图像就会显示出来。它适用于桌面(在 chrome 中测试,使用鼠标滚动和触摸模拟)但它不适用于移动设备上的 chrome。未检测到滑动(触摸滚动)。页面下降但图像没有得到那个.show。我在 fullpage.js+iscroll.js 页面中使用它。
您可以在以下网址尝试:http://www.vinarijapantic.com/apps/onePage/project.html
有什么想法吗?
jQuery(document).ready(function($) {
function showImages(el) {
var windowHeight = jQuery(window).height();
$(el).each(function() {
var thisPos = $(this).offset().top;
var topOfWindow = $(window).scrollTop();
if (topOfWindow + windowHeight - 250 > thisPos) {
$(this).addClass("show");
}
});
}
/*full page library */
var SCROLLING_SPEED = 600;
$('#fullpage').fullpage({
scrollOverflow: true,
css3: true,
controlArrows: true,
loopHorizontal: false,
easing: 'easeInOutCubic',
easingcss3: 'ease-out',
autoScrolling: true,
scrollingSpeed: SCROLLING_SPEED,
//anchors:['s0', 's1', 's2', 's3']
afterLoad: function(anchorLink, index) {
},
afterSlideLoad: function(anchorLink, index, slideAnchor, slideIndex) {
if (slideIndex == 0) {
$('.slide-' + index).addClass('show');
} else {
$('.slide').removeClass('show');
}
if ($('.bigScroll').hasClass('active') && $('.bigScroll').closest('.section').hasClass('active')) {
console.log($(".bigScroll").height());
showImages('.bigScroll img');
$('.fp-scrollable').scroll(function() {
showImages('.bigScroll img');
});
}
}
});
});
最佳答案
在移动网络上启用 JavaScript
有些情况下浏览器会抛出这样的错误 “当试图访问 ------- 在移动设备上时” 这意味着您设备上的网络浏览器需要在加载页面之前打开 JavaScript。
要打开 JavaScript,请打开移动网络浏览器的设置菜单并查找 JavaScript 选项。
关于javascript - 滚动淡入在移动浏览器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34467473/