【问题标题】:Add to div margin if less than total height如果小于总高度,则添加到 div 边距
【发布时间】:2023-03-11 07:10:02
【问题描述】:

我正在尝试构建一个滑块,该滑块将在单击时上下移动多个 div。当我到达 div 的末尾时,我希望滑块停止。我真的坚持检查我们是否在最后一个 div。

我的 div 是绝对定位的,滑动容器的高度是通过将所有这些加在一起来计算的,然后我将使用边距来上下移动滑动容器。

如何在我的 if 语句中进行比较,margin-top + 下一个 div 高度将小于总高度(即防止在一个方向上无限添加)?

if($('#slide-container').css({'marginTop': +=59} < $('#slide-container').height()) {
    // Go back to 0
}

其中 59 是移动 div 的高度,因此我们在每次点击时添加 this 的边距。这个 if 语句应该检查我们是否在最后一个。

谢谢,

【问题讨论】:

标签: jquery animation slider margin


【解决方案1】:

我想我找到了一个可行的解决方案。您需要导入 jQuery UI 来运行它。而且你必须编写一个以前的点击函数。但这是下一个功能:

http://jsfiddle.net/88wHu/2/

代码如下:

$(document).ready(function(){
    var hideoptions = {  "direction" : "up",  "mode" : "hide"};
    var showoptions = {"direction" : "down","mode" : "show"};
    $('.webinar').not(':first-child').hide();
    $('.webinar:first-child').addClass('active-slide');
    $('span.next-arw').click(function(e){
        if($('.active-slide').next().length>0){
            console.log($('.active-slide').next());
            var current=$('.active-slide');
            var current_next=current.next();
            current_next.addClass('active-slide');
            current.removeClass('active-slide');

            current.effect( "slide", hideoptions, 400);            
            current_next.effect( "slide", showoptions, 400);          

        }
    });


});

希望对你有所帮助:)

【讨论】:

  • 没问题!感谢您喜欢并接受答案:)
猜你喜欢
  • 1970-01-01
  • 2023-03-26
  • 2013-08-10
  • 1970-01-01
  • 2012-04-03
  • 1970-01-01
  • 2014-02-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多