Javascript 带幻灯片的Body lock全屏部分
我有一个一页的网站和部分。在用户浏览幻灯片时使用+中间部分 如果用户向下滚动,则主体锁定应处于活动状态,直到最后一张幻灯片,反之亦然,如果用户向后滚动到页面顶部Javascript 带幻灯片的Body lock全屏部分,javascript,jquery,swiper,Javascript,Jquery,Swiper,我有一个一页的网站和部分。在用户浏览幻灯片时使用+中间部分 如果用户向下滚动,则主体锁定应处于活动状态,直到最后一张幻灯片,反之亦然,如果用户向后滚动到页面顶部 // body lock while going down window.addEventListener("scroll", function() { var elementTarget = document.getElementById("the-dashboard"); if (window.scrollY > el
// body lock while going down
window.addEventListener("scroll", function() {
var elementTarget = document.getElementById("the-dashboard");
if (window.scrollY > elementTarget.offsetTop + elementTarget.offsetHeight) {
$('html').addClass('no-scroll') // locks
}
});
// SWIPER
var leftSwiper = new Swiper(".swiper-container-left", {
direction: "vertical",
mousewheel: {
invert: true,
mousewheelReleaseOnEdges: true
},
allowTouchMove: false,
initialSlide: 3
});
var rightSwiper = new Swiper(".swiper-container-right", {
direction: "vertical",
mousewheel: true,
mousewheelReleaseOnEdges: true,
pagination: {
el: ".swiper-pagination"
},
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev"
}
});
rightSwiper.on("reachEnd", function() {
$('html').removeClass('no-scroll') // unlocks but the first lock still active and locks it again
});
问题:
无法再次解锁屏幕,因为用户已“通过”div顶部,而未使用窗口顶部“触摸”div顶部
可能的解决方案:
一个很好的方法是在到达区段顶部时锁定区段,直到触发Swiper“Reachen”事件
查看画笔:可以使用鼠标滚轮事件在此画笔上找到javascript解决方案: 代码:
window.addEventListener("scroll", function() {
$target = $("#swipes");
if (window.scrollY > $target[0].offsetTop && window.scrollY < $target[0].offsetTop + 150) {
$('html').addClass('no-scroll');
}
else {
$('html').removeClass('no-scroll');
}
});
var leftSwiper = new Swiper(".swiper-container-left", {
direction: "vertical",
/** mousewheel: {
invert: true,
mousewheelReleaseOnEdges: true
},
**/
allowTouchMove: false,
initialSlide: 3
});
var rightSwiper = new Swiper(".swiper-container-right", {
direction: "vertical",
/** mousewheel: true,
mousewheelReleaseOnEdges: true, */
pagination: {
el: ".swiper-pagination"
},
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev"
}
});
leftSwiper.on("slideNextTransitionStart", function() {
rightSwiper.slidePrev(500, false);
});
leftSwiper.on("slidePrevTransitionStart", function() {
rightSwiper.slideNext(500, false);
});
rightSwiper.on("slideNextTransitionStart", function() {
leftSwiper.slidePrev(500, false);
});
rightSwiper.on("slidePrevTransitionStart", function() {
leftSwiper.slideNext(500, false);
});
rightSwiper.on("reachEnd", function() {
});
rightSwiper.on("reachBeginning", function() {
});
var waiting = false;
$(window).bind('mousewheel', function(event) {
if ($('html').hasClass('no-scroll')) {
if (event.originalEvent.wheelDelta >= 0) {
if (waiting == false) {
l = leftSwiper.slideNext();
if (l == false) {
$('html').removeClass('no-scroll');
console.log('top');
console.log($(window));
} else {
waiting = true;
setTimeout(function () {
waiting = false;
},500);
}
}
}
else {
if (waiting == false) {
var r = rightSwiper.slideNext();
if (r == false) {
$('html').removeClass('no-scroll');
} else {
waiting = true;
setTimeout(function () {
waiting = false;
}, 500);
}
}
}
}
});
$(document).on('mousewheel', function() {
$(document).trigger('mousewheel');
});
window.addEventListener(“滚动”,函数(){
$target=$(“#刷”);
if(window.scrollY>$target[0]。offsetTop&&window.scrollY<$target[0]。offsetTop+150){
$('html').addClass('no-scroll');
}
否则{
$('html').removeClass('no-scroll');
}
});
var leftSwiper=new Swiper(“.Swiper容器左”{
方向:“垂直”,
/**鼠标滚轮:{
颠倒:是的,
鼠标滚轮释放键:true
},
**/
allowTouchMove:false,
首张幻灯片:3
});
var rightSwiper=newswiper(“.Swiper容器权限”{
方向:“垂直”,
/**鼠标轮:是的,
鼠标滚轮释放键:正确*/
分页:{
el:“.swiper分页”
},
导航:{
nextEl:“.swiper按钮下一步”,
prevEl:“.swiper按钮prev”
}
});
leftSwiper.on(“slideNextTransitionStart”,函数(){
右旋转滑块EV(500,假);
});
on(“slidePrevTransitionStart”,函数(){
rightSwiper.slideNext(500,false);
});
rightSwiper.on(“slideNextTransitionStart”,函数(){
slidePrev(500,假);
});
on(“slidePrevTransitionStart”,函数(){
leftSwiper.slideNext(500,false);
});
rightSwiper.on(“reachEnd”,function()){
});
rightSwiper.on(“reachBeginning”,函数(){
});
var=false;
$(窗口).bind('mousewheel',函数(事件){
if($('html').hasClass('no-scroll')){
如果(event.originalEvent.wheelDelta>=0){
if(waiting==false){
l=leftSwiper.slideNext();
如果(l==false){
$('html').removeClass('no-scroll');
console.log('top');
console.log($(窗口));
}否则{
等待=真;
setTimeout(函数(){
等待=错误;
},500);
}
}
}
否则{
if(waiting==false){
var r=rightSwiper.slideNext();
如果(r==false){
$('html').removeClass('no-scroll');
}否则{
等待=真;
setTimeout(函数(){
等待=错误;
}, 500);
}
}
}
}
});
$(document).on('mouseweel',function(){
$(document.trigger('mouseweel');
});
(不是我)