jQuery上一个/下一个导航,带有用于自定义日历的显示/隐藏内容

麦克风

我想通过显示/隐藏内容来创建一些上一个/下一个日历解决方案。

我有以下用于导航的代码(应该增加几个月的时间来保持灵活性):

<div class="months">
    <div class="082016">2016 august</div>
    <div class="092016">2016 september</div>
    <div class="102016">2016 october</div>
</div>

和项目:

<div class="items">
    <div id="082016">
        <div class="item">August item</div>
        <div class="item">August item</div>
        <div class="item">August item</div>
    </div>
    <div id="092016">
        <div class="item">September item</div>
        <div class="item">September item</div>
        <div class="item">September item</div>
    </div>
    <div id="102016">
        <div class="item">October item</div>
        <div class="item">October item</div>
        <div class="item">October item</div>
    </div>
</div>

我要实现的是进行这样的导航:

八月日历项

9月日历项目

十月日历项目

因此,在箭头上单击它将显示该月份的ID,并将更改导航标题。我也应该没有第一个月的后退箭头,也没有下个月的下一个箭头。

在此先感谢您的帮助!

盖塔诺

我对您的问题的建议是一个纯jQuery脚本:

$(function () {
  var cachedToDivs = $('.months div');

  cachedToDivs.css({'font-weight': 'bold'});
  $('.items > div:lt(' + (cachedToDivs.length - 1) + ')').hide();
  $('.months div:lt(' + (cachedToDivs.length - 1) + ')').hide();


  cachedToDivs.on('click', 'img', function (e) {
    if ($(':animated').length > 0) {
      return; // wait for last animation...
    }
    var index;
    if (e.target.name == 'prev') {
      index = (-1 + $(this).parent().index()) % cachedToDivs.length;
      index = (index < 0) ? cachedToDivs.length - 1: index;
    } else {
      index = (1 + $(this).parent().index()) % cachedToDivs.length;
    }
    cachedToDivs.eq(index).find('img').remove();
    var txt = cachedToDivs.eq(index).text().trim();
    cachedToDivs.eq(index).html('<img name="prev" src="http://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/256/Actions-go-previous-icon.png" width="20" height="15"/>&nbsp;&nbsp;&nbsp;' + txt + '&nbsp;&nbsp;&nbsp;<img  name="next" src="http://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/256/Actions-go-next-icon.png" width="20" height="15"/>');
    $(this).parent().hide();
    cachedToDivs.eq(index).show();
    $('.items > div:visible').slideUp('fast', function() {
      $('.items #' + cachedToDivs.eq(index).attr('class')).slideDown('fast');
    })
    if(index == (cachedToDivs.length - 1)) {  // on the last month remove next image
      cachedToDivs.eq(index).find('img[name="next"]').remove();
    }
    if(index == 0) {  // on the first month remove prev image
      cachedToDivs.eq(index).find('img[name="prev"]').remove();
    }
  });
  cachedToDivs.eq((cachedToDivs.length - 1)).html('<img name="prev" src="http://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/256/Actions-go-previous-icon.png" width="20" height="15"/>&nbsp;&nbsp;&nbsp;' + cachedToDivs.eq(2).text().trim() + '&nbsp;&nbsp;&nbsp;<img  name="next" src="http://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/256/Actions-go-next-icon.png" width="20" height="15"/>');
  $('.months div:visible img[name="next"]').trigger('click');
});
.months {
  display: inline-block;
}
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>

<div class="months">
    <div class="082016">2016 august</div>
    <div class="092016">2016 september</div>
    <div class="102016">2016 october</div>
</div>
<div class="items">
    <div id="082016">
        <div class="item">August item</div>
        <div class="item">August item</div>
        <div class="item">August item</div>
    </div>
    <div id="092016">
        <div class="item">September item</div>
        <div class="item">September item</div>
        <div class="item">September item</div>
    </div>
    <div id="102016">
        <div class="item">October item</div>
        <div class="item">October item</div>
        <div class="item">October item</div>
    </div>
</div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在wordpress的下一个和上一个链接中显示自定义字段数据

自定义分页,用箭头代替下一个上一个

vue 自定义滑块,下一个和上一个按钮

jQuery的简单下一个和上一个显示和隐藏

带有上一个和下一个按钮的循环显示

带有下一个上一个jquery的SlideShow

具有自定义字段类别的下一个/上一个自定义帖子类型

带有日期时间字段的Rails模型下一个/上一个导航范围

自定义上一个/下一个分页图标背景颜色与Material UI

如何禁用自定义滑块中的“上一个”和“下一个”按钮?

Angular Primeng转盘-自定义上一个和下一个按钮

AngularJS UI轮播自定义上一个和下一个按钮

如何为该自定义滚动添加下一个和上一个按钮?

反应表中的自定义“上一个”和“下一个”文本

创建自定义分页,但是“下一个”和“上一个”按钮不起作用

JavaScript-如何显示下一个div并隐藏上一个div?

如何显示下一个div并隐藏上一个div?

显示下一个之前无法隐藏上一个窗口

全日历多个日历,如何单击所有日历的上一个/下一个

jQuery,Bootstrap导航-如何添加上一个/下一个按钮?

如何隐藏jquery datepicker上一个/下一个文本

带有上一个和下一个图像的图像滑块

jQuery隐藏当前div并显示下一个

上一个和下一个按钮不适用于Angular Bootstrap日历

下一个和上一个按钮不适用于多个日历

全日历视图显示goToDate打破上一个,下一个和今天

jQuery滑块在上一个或最后一个时隐藏上一个和下一个

代号下一个/上一个月份的日历事件

jQuery将自定义标签移至下一个