幻灯片放映一次显示2张图片

时间:2017-07-06 22:02:49

标签: javascript html css

我尝试通过透明度进行幻灯片放映,但问题是当我有4张图像和第4张图像随第1张变化时,第1幅图像可能以某种方式提前显示并将第3张图像向下推。另一个问题是当第3张图像改变第4张图像时,并没有像其他图像一样在他下面创建一些自由空间(如果分辨率不好则可能看不到)。当我添加超过4个图像并且始终只在最后一张图片上时,也会出现此问题。任何建议如何解决它和我做错了什么?



binomial(link = "logit")

var isFollowing: Bool!

// -------------------------------

if parseJSON["status"] as! String == "1"{
    self.followBtn.setTitle("Following", for: .normal)
    self.followBtn.backgroundColor = UIColor(red: 32, green: 113, blue: 165, alpha: 0.5)
    self.isFollowing = true
} else if parseJSON["status"] as! String == "0"{
    self.followBtn.setTitle("Follow", for: .normal)
    self.isFollowing = false
}

// -------------------------------

@IBAction func followUser(_ sender: Any) {
    if self.isFollowing {
        // whatever happens when you're already following
    } else {
        print("will follow")
    }
}

var slides = document.querySelectorAll('.imageSlide');
var currentSlide = 0;
var slideInterval = setInterval(nextSlide, 2000);

function nextSlide() {
  slides[currentSlide].className = "imageSlide";
  currentSlide = (currentSlide + 1) % slides.length;
  slides[currentSlide].className = "imageSlide showing";
}




1 个答案:

答案 0 :(得分:1)

问题是您对一个项目使用position: absolute position: static



.container {
  position: relative;
}

.item {
  position: absolute;
}

.showing {
  position: static;
  border: 1px solid;
}

<div class="container">
  <div class="item showing">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
  <div class="item">4</div>
</div>
&#13;
&#13;
&#13;

这就是你得到这种奇怪行为的原因。每件商品都必须在顶部。

.item {
    position: absolute;
    top: 0;
}

分别

.imageSlide {
    position: absolute;
    top: 0;
    ...
}