0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

jQuery 仮サイト作成のbase ② (自分用)

Posted at

ezgif.com-video-to-gif (2).gif

###前回の続き:スライドショーについてのみ###


  <div class="slick">
    <div class="single">
      <div><img src="image/802.jpg" alt=""></div>
      <div><img src="image/IMG_3943.jpg" alt=""></div>
      <div><img src="image/IMG_4259.jpg" alt=""></div>
      <div><img src="image/IMG_4926.jpg" alt=""></div>
      
    </div>
  </div>

jquery.js

var page=0;
var lastPage =parseInt($(".single img").length-1);

  $(".single img").css("display","none");
  $(".single img").eq(page).css("display","block");  //pageを取得

function changePage(){
  $(".single img").fadeOut(1000);
  $(".single img").eq(page).fadeIn(1000);          //一旦1秒で画像間の接続時間
};

var Timer;
function startTimer(){
Timer =setInterval(function(){
  if(page === lastPage){
     page = 0;
     changePage();
  }else{
     page ++;
     changePage();
  };},4000);                        //一旦4秒で次画像へ
};
}

startTimer();
styles.css

//cssは仮

.slick {
  width: 100%;
  height: 400px;
  position: relative;
  /* left: 0; */
  top: 260px;
 
}
.single {
  position: relative;
}
.single img {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  width: 100%;
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?