gpt4 book ai didi

javascript - jQuery:满足条件后更改类

转载 作者:可可西里 更新时间:2023-11-01 14:49:49 25 4
gpt4 key购买 nike

我创建了这个 site在 stackoverflow > here 上使用此示例,您有多个 slider 垂直移动<连同这个fiddle .

加载时网站溢出:隐藏在正文中,位置固定在我的主要内容 div(div class="content-fs row")。这个想法是,当你第一次到达页面时,你滚动浏览每张幻灯片,一旦你点击最后一张,主要内容 div(div class="content-fs row") 上的位置就会改变> 从 fixed 到 static 和 overflow: hidden 从正文中删除。我在编写“如果是最后一个 slider ,则更改位置”的条件语句时遇到问题。下面的 jquery 是我在网站上使用的代码以及不起作用的条件语句。

如有任何指点/建议,我们将不胜感激!

j查询:

function scrollLax(){
/*
initialize
*/
var scrollDown = false;
var scrollUp = false;
var scroll = 0;
var $view = $('#portfolio');
var t = 0;
var h = $view.height() - 250;


$view.find('.portfolio-sliders').each(function() {
var $moving = $(this);
// position the next moving correctly
if($moving.hasClass('from-bottom')) {
$moving.css('top', h); // subtract t so that a portion of the other slider is showing
}
// make sure moving is visible
$moving.css('z-index', 10);
});
var $moving = $view.find('.portfolio-sliders:first-child');
$moving.css('z-index', 10);

/*
event handlers
*/

var mousew = function(e) {
var d = 0;
if(!e) e = event;
if (e.wheelDelta) {
d = -e.wheelDelta/3;
} else if (e.detail) {
d = e.detail/120;
}
parallaxScroll(d);
}
if (window.addEventListener) {
window.addEventListener('DOMMouseScroll', mousew, false);
}
window.onmousewheel = document.onmousewheel = mousew;
/*
parallax loop display loop
*/
window.setInterval(function() {
if(scrollDown)
parallaxScroll(4);
else if(scrollUp)
parallaxScroll(-4);
}, 50);

function parallaxScroll(scroll) {
// current moving object
var ml = $moving.position().left;
var mt = $moving.position().top;
var mw = $moving.width();
var mh = $moving.height();
// calc velocity
var fromBottom = false;
var vLeft = 0;
var vTop = 0;
if($moving.hasClass('from-bottom')) {
vTop = -scroll;
fromBottom = true;
}
// calc new position
var newLeft = ml + vLeft;
var newTop = mt + vTop;
// check bounds
var finished = false;
if(fromBottom && (newTop < t || newTop > h)) {
finished = true;
newTop = (scroll > 0 ? t : t + h);
}

// set new position
$moving.css('left', newLeft);
$moving.css('top', newTop);
// if finished change moving object
if(finished) {
// get the next moving
if(scroll > 0) {
$moving = $moving.next('.portfolio-sliders');
if($moving.length == 0)
$moving = $view.find('.portfolio-sliders:last');
//this is where I am trying to add the if conditional statement.
if ('.portfolio-sliders:last')
$('.content-fs.row').css({'position': 'static'});
if('.portfolio-sliders:last' && (mt == 0))
$('html, body').removeClass('overflow');
} else {
$moving = $moving.prev('.portfolio-sliders');
if($moving.length == 0)
$moving = $view.find('.portfolio-sliders:first-child');
//reverse the logic and if last slide change position
if('.portfolio-sliders:first-child')
$('.content-fs.row').css({'position': 'fixed'});
}

}
// for debug
//$('#direction').text(scroll + "/" + t + " " + ml + "/" + mt + " " + finished + " " + $moving.text());

}

}

最佳答案

您的代码只是询问 .portfolio-sliders:last 是否存在。看来你应该这样做:

if ($moving == $('.portfolio-sliders:last') )

或类似的东西,而不是检查事件幻灯片是否是最后一张。

关于javascript - jQuery:满足条件后更改类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21790207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com