Skip to content

Instantly share code, notes, and snippets.

@ynunokawa
Last active November 25, 2016 06:09
Show Gist options
  • Save ynunokawa/bab7546fee0ff8725144b604ebf1414b to your computer and use it in GitHub Desktop.
Save ynunokawa/bab7546fee0ff8725144b604ebf1414b to your computer and use it in GitHub Desktop.
最小コードの CSS でスクロール時のイライラを解消する for Leaflet.js
<html>
<head>
<meta charset=utf-8 />
<title>最小コードの CSS でスクロール時のイライラを解消する for Leaflet.js</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<!-- Load Leaflet from CDN-->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.2/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.0.2/dist/leaflet.js"></script>
<style>
body { margin:0; padding:15px; }
.image-content {
position: relative;
top:0;
bottom:0;
right:0;
left:0;
margin:0;
height: 200px;
background-image: url(https://esrijapan.github.io/photospot-finder/img/kujiranspot-bg.jpg);
background-size: cover;
}
#map {
position: relative;
top:0;
bottom:0;
right:0;
left:0;
margin:0;
height:300px;
}
#mapView {
position: absolute;
top:0;
bottom:0;
right:0;
left:0;
margin:0;
}
/* こっから下がポイント */
.cover-text {
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
color: #fff;
height: 32px;
width: 200px;
position: absolute;
z-index: 9999;
text-align: center;
font-family: "Meiryo";
font-size: 0.6em;
border-radius: 17px;
border: solid 1px #fff;
}
.cover {
background-color: #000;
opacity: 0.4;
height: 100%;
width: 100%;
position: absolute;
z-index: 9999;
transition: opacity 0.4s;
}
#map:hover > .cover-text:hover, .cover:hover, .cover:hover + .cover-text {
display: none;
}
#map:active > .cover, #map:active > .cover-text {
opacity: 0;
}
</style>
</head>
<body ontouchstart="">
<div class="image-content"></div>
<div class="image-content"></div>
<div class="image-content"></div>
<div class="image-content"></div>
<div id="map">
<div id="mapView"></div>
<div class="cover"></div>
<div class="cover-text"><p>地図を操作する</p></div>
</div>
<div class="image-content"></div>
<div class="image-content"></div>
<div class="image-content"></div>
<div class="image-content"></div>
<script>
var map = L.map('mapView').setView([51.505, -0.09], 13);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.marker([51.5, -0.09]).addTo(map)
.bindPopup('CSS だけでスクロール時の<br>イライラを解消してみた!!')
.openPopup();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment