【问题标题】:Carousel by increasing z-index in Dart Language?通过增加 Dart 语言中的 z-index 来旋转木马?
【发布时间】:2013-08-20 05:48:49
【问题描述】:

我正在尝试使用 Dart 语言实现轮播,并将多个 Div 放置在父 div 中。单击右键时,下一个 div 的 z-index 必须高于前一个才能显示。我已将所有 div 类名存储在 arraylist 中。现在任何人都可以帮助完成这项工作吗? HTML

<div class="carousel">
  <div class="galleryCars">
  ....
  </div>
  <div class="galleryCars2">
  ....
  </div>
  <div class="galleryCars3">
  ....
  </div>
  <div class="galleryCars4">
  ....
  </div>
</div>

飞镖

import 'dart:html';
import 'dart:core';
void main(){
    query(".rightArrow img").onClick.listen((e) => cssRightArrow());
    query(".leftArrow img").onClick.listen((e) => cssLeftArrow());
}
cssRightArrow(){
  var carousel = query(".carousel");
  var classList = [];
  carousel.children.forEach(
      (childElement) => childElement.classes.forEach(
          (className) => classList.add(className)
          ));

  /*for (var i = 0; i < classList.length; i++) {                
    var zIndexElem = query(".${classList[i]}");
    var newIndex = int.parse(zIndexElem.style.zIndex ) + 10 ;   
    zIndexElem.style.zIndex = "${newIndex}";
    }*/ //Not Working
}

【问题讨论】:

    标签: dart carousel dart-webui


    【解决方案1】:

    这是一个使用style.display = 'none' 而不是zIndex 的工作示例(我认为zIndex 不太适合这个用例。):

    import 'dart:html';
    
    void main(){
      query(".rightArrow img").onClick.listen((e) => cssRightArrow());
      query(".leftArrow img").onClick.listen((e) => cssLeftArrow());
    }
    cssRightArrow(){
      final elements = query(".carousel").children;
    
      // looking for the one currently displayed
      final Element current = elements.firstWhere((e) => e.style.display != 'none');
      final currentIndex = elements.indexOf(current);
    
      // hide current and show next one
      if (currentIndex + 1 < elements.length) {
        current.style.display = 'none';
        elements[currentIndex + 1].style.display = '';
      }
    }
    

    【讨论】:

    • final Element current = elements.firstWhere((e) => e.style.display != 'none'); 这里我需要再做一个style position absolute .我应该如何进行事件调用??
    • style.display(用于显示类型)和style.position(用于absolute定位)是style的两个不同属性,可以独立设置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-27
    • 2012-12-24
    • 1970-01-01
    • 1970-01-01
    • 2022-08-03
    • 2014-02-01
    • 1970-01-01
    相关资源
    最近更新 更多