swiper.jsを使って横スワイプと画像のピンチ拡大縮小に対応させたときのメモ。
拡大縮小させたい画像をswiper-zoom-containerで囲ってオプションにzoomを設定すればよいみたい。
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>タイトル</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css" />
</head>
<body>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide"><div class="swiper-zoom-container"><img src="img/001.jpg" alt="sample001"></div></div>
<div class="swiper-slide"><div class="swiper-zoom-container"><img src="img/002.jpg" alt="sample002"></div></div>
<div class="swiper-slide"><div class="swiper-zoom-container"><img src="img/003.jpg" alt="sample003"></div></div>
<div class="swiper-slide"><div class="swiper-zoom-container"><img src="img/004.jpg" alt="sample004"></div></div>
<div class="swiper-slide"><div class="swiper-zoom-container"><img src="img/005.jpg" alt="sample005"></div></div>
</div><!--/.swiper-wrapper-->
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div><!--/.swiper-container-->
<script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
var swiper = new Swiper('.swiper-container', {
loop: true,
//initialSlide: 3,
autoHeight: true,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
zoom: {
maxRatio: 5, // Maximum zoom level
}
});
});
</script>
</body>
</html>
zoomオプションの存在に気が付いていなかった・・・。