3

浏览http://foundation.zurb.com/docs/components/section.html,无论如何我可以为部分标题(标签)添加水平滚动。我在水平滚动的基础部分中看起来像http://www.seyfertdesign.com/jquery/ui.tabs.paging.html并继续在小屏幕中使用手风琴

4

3 回答 3

1

我为那些感兴趣的人找到了一个解决方案:https ://codepen.io/gdyrrahitis/pen/BKyKGe

.tabs {
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  .tabs-title {
    float: none;
    display: inline-block;
  }
}
于 2017-06-16T13:07:33.330 回答
0

如果有人需要带有 jquery 实现的 angularjs,下面的代码可以帮助您,对于纯 jquery,将 angularjs 指令方法替换为具有相应属性的本机 js 方法。

我试图搜索类似的实现但一无所获,所以我编写了一个简单的角度指令,可以将基础 CSS 选项卡转换为可滚动选项卡

angular.module("app.directives.scrollingTabs", [])
.directive("scrollingTabs", ScrollingTabsDirective);
//@ngInject
function ScrollingTabsDirective($timeout, $window) {
return {
  restrict: 'A',
  link: function (scope, element, attr) {
    if(attr.scrollingTabs == "true"){
      element.addClass('scrolling-tabs-container');
      element.find('.nav-buttons').remove();
      element.append('<div class="scrolling-tabs nav-buttons nav-buttons-left"></div>');
      element.append('<div class="scrolling-tabs nav-buttons nav-buttons-right"></div>');

      let scrolledDiv = $(element).find('.tabs');
      let scrolled;
      let scrolling;

      let scrollFn = (step, animationTime, cb) => {
        scrolled = Math.max(scrolled + step, 0);
        scrolledDiv.animate({
          scrollLeft:  scrolled
        }, animationTime, ()=>{
          if (scrolling) {
            scrollFn(step, animationTime, cb)
          }else{
            if(cb){cb()}
          }
        });
      };

      let checkActiveNavButtonsClasses = () => {
        scrolled = scrolledDiv.scrollLeft();
        let scrollWidth = scrolledDiv.get(0).scrollWidth;
        let scrolledDivWidth = scrolledDiv.get(0).clientWidth;

        if(scrollWidth > scrolledDivWidth){
          element.addClass('nav-active');
          scrollWidth = scrolledDiv.get(0).scrollWidth;
          if(scrolled == 0){
            element.removeClass('nav-active-left').addClass('nav-active-right')
          }else if(scrolled > 0 && scrolled + scrollWidth < scrolledDivWidth){
            element.addClass('nav-active-left').addClass('nav-active-right');
          }else if(scrolled > 0 && scrolled + scrollWidth >= scrolledDivWidth){
            element.addClass('nav-active-left').removeClass('nav-active-right');
          }else{
            element.removeClass('nav-active-left').removeClass('nav-active-right')
          }
        }else{
          element.removeClass('nav-active-left').removeClass('nav-active-right').removeClass('nav-active');
        }
      };

      let scrollToActiveTab = () => {
        let activeDD = scrolledDiv.find('dd.active');
        let tabsOffset = scrolledDiv.offset();
        let activeTaboffset = activeDD.offset();
        let activeTabwidth = activeDD.width();
        let scrolledStep = activeTaboffset.left - tabsOffset.left - scrolledDiv.width() + activeTabwidth;

        scrollFn(scrolledStep, 100, checkActiveNavButtonsClasses);
      };

      element.find(".nav-buttons.nav-buttons-left")
        .off("click.scrolling")
        .on("click.scrolling", (event)=>{
          event.preventDefault();
          scrolling = false;
          scrollFn(-100, 100, checkActiveNavButtonsClasses);
        })
        .off("mouseover.scrolling")
        .on("mouseover.scrolling", function (event) {
          scrolling = true;
          scrollFn(-2, 1, checkActiveNavButtonsClasses);
        })
        .off("mouseout.scrolling")
        .on("mouseout.scrolling", function (event) {
          scrolling = false;
        });

      element.find(".nav-buttons.nav-buttons-right")
        .off("click.scrolling")
        .on("click.scrolling", (event)=>{
          event.preventDefault();
          scrolling = false;
          scrollFn(100, 100, checkActiveNavButtonsClasses);
        })
        .off("mouseover.scrolling")
        .on("mouseover.scrolling", function (event) {
          scrolling = true;
          scrollFn(2, 1, checkActiveNavButtonsClasses);
        })
        .off("mouseout.scrolling")
        .on("mouseout.scrolling", function (event) {
          scrolling = false;
        });

      $timeout(()=>{
        checkActiveNavButtonsClasses();
        scrollToActiveTab()
      },1000);

      $($window).off('resize.scrolling').on('resize.scrolling', _.debounce(()=> {
        checkActiveNavButtonsClasses();
      }, 500));

      scope.$on('$destroy', function() {
        $($window).off('resize.scrolling');
      });
    }
  }
}}

CSS:

.scrolling-tabs-container {
position: relative;
.tabs {
overflow-x: hidden;
white-space: nowrap;
-webkit-overflow-scrolling: touch;
display: block;
margin-right: 18px;

dd {
  display: inline-block;
  float: none;
  margin: 0px -3px 0px 0px;

}

.tabs-title {
  float: none;
  display: inline-block;
}
}
.scrolling-tabs {
&.nav-buttons {
  display: none;
  position: absolute;
  width: 19px;
  height: 38px;
  border: 1px solid #c1c1c1;
  top: 1px;
  background-color: rgba(255, 255, 255, 0.5);
  opacity: 0.4;
  cursor: pointer;
  &:hover {
    opacity: 1;
    &:before {
      color: #444;
    }
  }
  &:before {
    position: absolute;
    left: 7px;
    top: 8px;
    color: #777;
  }
  &.nav-buttons-left {
    left: 0;
    &:before {
      content: '<';
    }
  }
  &.nav-buttons-right {
    right: 18px;
    &:before {
      content: '>';
    }
  }
}
}
&.nav-active{
.tabs{
  margin-right: 36px;
  margin-left: 18px;
}
.scrolling-tabs {
  &.nav-buttons {
    display: inline-block !important;
  }
}
}
&.nav-active-left{
.scrolling-tabs{
  &.nav-buttons-left{
    opacity: 0.8;
  }
}
}
&.nav-active-right{
.scrolling-tabs{
  &.nav-buttons-right{
    opacity: 0.8;
  }
}}}

HTML:基础选项卡模板。

<tabset class="list-tabs" scrolling-tabs="true">
    <tab heading="tab1"></tab>
    <tab heading="tab2"></tab>
   <tab heading="tab2"></tab>
</tabset>
于 2018-06-27T21:55:14.703 回答
-1

在开始之前,您需要验证 jQuery(或 Zepto)和foundation.js 在您的页面上是否可用。这些带有基础包,因此只需在您的页脚中取消注释或相应地包含它们。

<div class="section-container auto" data-section>
  <section class="active">
    <p class="title" data-section-title><a href="#panel1">Section 1</a></p>
    <div class="content" data-section-content>
      <p>Content of section 1.</p>
    </div>
  </section>
  <section>
    <p class="title" data-section-title><a href="#panel2">Section 2</a></p>
    <div class="content" data-section-content>
      <p>Content of section 2.</p>
    </div>
  </section>
</div>

基金会文档包含所有相关信息:

http://foundation.zurb.com/docs/components/section.html#panel2

这将为您提供部分表格标题。然后,您希望将内容管理为可滚动。

<div class="content" data-section-content>
      <p>Content of section 1.</p>
    </div>

这里的内容将是工作的领域,尝试添加一个名为的新类.scrollable

在这个类中使用类似的东西:

.scrollable{
  overflow:scroll;
}

您可能希望为此添加更多内容,但这将使您入门。您的 HTML 现在应该如下所示:

<div class="content scrollable" data-section-content>
  <p>Content of section 1. This content will be scrollable when the content has exceeded that of the div size. </p>
</div>

这就是你要找的。

于 2013-10-21T08:27:56.447 回答