HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<h3>ギャラリー01</h3>
<div class="ps_area photoswipe_gallery">
<a href="https://125naroom.com/wp/wp-content/uploads/2015/02/sora17.jpg" data-size="600x600" data-med="https://125naroom.com/wp/wp-content/uploads/2015/02/sora17.jpg" data-med-size="600x600" data-author="125naroom">
<img src="https://125naroom.com/wp/wp-content/uploads/2015/02/sora17.jpg" alt="">
<figure>sora 1</figure>
</a>
<a href="https://125naroom.com/wp/wp-content/uploads/2015/02/sora16.jpg" data-size="600x600" data-med="https://125naroom.com/wp/wp-content/uploads/2015/02/sora16.jpg" data-med-size="600x600" data-author="125naroom">
<img src="https://125naroom.com/wp/wp-content/uploads/2015/02/sora16.jpg" alt="">
<figure>sora 2</figure>
</a>
<a href="https://125naroom.com/wp/wp-content/uploads/2015/02/sora15.jpg" data-size="600x600" data-med="https://125naroom.com/wp/wp-content/uploads/2015/02/sora15.jpg" data-med-size="600x600" data-author="125naroom">
<img src="https://125naroom.com/wp/wp-content/uploads/2015/02/sora15.jpg" alt="">
<figure>sora 3</figure>
</a>
<a href="https://125naroom.com/wp/wp-content/uploads/2015/02/sora10.jpg" data-size="600x600" data-med="https://125naroom.com/wp/wp-content/uploads/2015/02/sora10.jpg" data-med-size="600x600" data-author="125naroom">
<img src="https://125naroom.com/wp/wp-content/uploads/2015/02/sora10.jpg" alt="">
<figure>sora 4</figure>
</a>
<a href="https://125naroom.com/wp/wp-content/uploads/2015/02/sora12.jpg" data-size="600x600" data-med="https://125naroom.com/wp/wp-content/uploads/2015/02/sora12.jpg" data-med-size="600x600" data-author="125naroom">
<img src="https://125naroom.com/wp/wp-content/uploads/2015/02/sora12.jpg" alt="">
<figure>sora 5</figure>
</a>
</div>
<h3>ギャラリー02</h3>
<div class="ps_area photoswipe_gallery">
<a href="https://125naroom.com/wp/wp-content/uploads/2015/02/sora01.jpg" data-size="600x600" data-med="https://125naroom.com/wp/wp-content/uploads/2015/02/sora01.jpg" data-med-size="600x600" data-author="125naroom">
<img src="https://125naroom.com/wp/wp-content/uploads/2015/02/sora01.jpg" alt="">
<figure>sora 1</figure>
</a>
<a href="https://125naroom.com/wp/wp-content/uploads/2015/02/sora02.jpg" data-size="600x600" data-med="https://125naroom.com/wp/wp-content/uploads/2015/02/sora02.jpg" data-med-size="600x600" data-author="125naroom">
<img src="https://125naroom.com/wp/wp-content/uploads/2015/02/sora02.jpg" alt="">
<figure>sora 2</figure>
</a>
<a href="https://125naroom.com/wp/wp-content/uploads/2015/02/sora03.jpg" data-size="600x600" data-med="https://125naroom.com/wp/wp-content/uploads/2015/02/sora03.jpg" data-med-size="600x600" data-author="125naroom">
<img src="https://125naroom.com/wp/wp-content/uploads/2015/02/sora03.jpg" alt="">
<figure>sora 3</figure>
</a>
<a href="https://125naroom.com/wp/wp-content/uploads/2015/02/sora04.jpg" data-size="600x600" data-med="https://125naroom.com/wp/wp-content/uploads/2015/02/sora04.jpg" data-med-size="600x600" data-author="125naroom">
<img src="https://125naroom.com/wp/wp-content/uploads/2015/02/sora04.jpg" alt="">
<figure>sora 4</figure>
</a>
<a href="https://125naroom.com/wp/wp-content/uploads/2015/02/sora05.jpg" data-size="600x600" data-med="https://125naroom.com/wp/wp-content/uploads/2015/02/sora05.jpg" data-med-size="600x600" data-author="125naroom">
<img src="https://125naroom.com/wp/wp-content/uploads/2015/02/sora05.jpg" alt="">
<figure>sora 5</figure>
</a>
</div>
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
<div class="pswp__bg"></div>
<div class="pswp__scroll-wrap">
<div class="pswp__container">
<div class="pswp__item"></div>
<div class="pswp__item"></div>
<div class="pswp__item"></div>
</div>
<div class="pswp__ui pswp__ui--hidden">
<div class="pswp__top-bar">
<div class="pswp__counter"></div>
<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
<button class="pswp__button pswp__button--share" title="Share"></button>
<button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
<button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
<div class="pswp__preloader">
<div class="pswp__preloader__icn">
<div class="pswp__preloader__cut">
<div class="pswp__preloader__donut"></div>
</div>
</div>
</div>
</div>
<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
<div class="pswp__share-tooltip"></div>
</div>
<button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button>
<button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button>
<div class="pswp__caption">
<div class="pswp__caption__center"></div>
</div>
</div>
</div>
</div>
/*==========
photoswipe_style
===========*/
.ps_area {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
max-width: 600px;
margin: 0 auto;
}
.ps_area:after {
content: "";
display: block;
width: 32.5%;
}
.ps_area a {
width: 32.5%;
margin-bottom: 1.25%;
transition-duration: 0.3s;
}
.ps_area a:hover {
opacity: .7;
cursor: zoom-in;
}
.ps_area a img {
width: 100%;
height: auto;
vertical-align: top;
}
.ps_area figure {
display: none;
}
/*==========
以下は不要です。
===========*/
body {
padding: 0 20px 50px;
font-family: YuGothic, "游ゴシック体", "Yu Gothic", "ヒラギノ角ゴ Pro", "Hiragino Kaku Gothic Pro", "メイリオ", Meiryo, "MS Pゴシック", "MS PGothic", sans-serif;
font-size: 16px;
letter-spacing: .025em;
line-height: 1.8;
margin: 0;
}
h3 {
text-align: center;
margin: 60px 0 30px;
}
// .photoswipe_gallery
(function() {
var initPhotoSwipeFromDOM = function(gallerySelector) {
var parseThumbnailElements = function(el) {
var thumbElements = el.childNodes,
numNodes = thumbElements.length,
items = [],
el,
childElements,
thumbnailEl,
size,
item;
for(var i = 0; i < numNodes; i++) {
el = thumbElements[i];
// include only element nodes
if(el.nodeType !== 1) {
continue;
}
childElements = el.children;
size = el.getAttribute('data-size').split('x');
// create slide object
item = {
src: el.getAttribute('href'),
w: parseInt(size[0], 10),
h: parseInt(size[1], 10),
author: el.getAttribute('data-author')
};
item.el = el; // save link to element for getThumbBoundsFn
if(childElements.length > 0) {
item.msrc = childElements[0].getAttribute('src'); // thumbnail url
if(childElements.length > 1) {
item.title = childElements[1].innerHTML; // caption (contents of figure)
}
}
var mediumSrc = el.getAttribute('data-med');
if(mediumSrc) {
size = el.getAttribute('data-med-size').split('x');
// "medium-sized" image
item.m = {
src: mediumSrc,
w: parseInt(size[0], 10),
h: parseInt(size[1], 10)
};
}
// original image
item.o = {
src: item.src,
w: item.w,
h: item.h
};
items.push(item);
}
return items;
};
// find nearest parent element
var closest = function closest(el, fn) {
return el && ( fn(el) ? el : closest(el.parentNode, fn) );
};
var onThumbnailsClick = function(e) {
e = e || window.event;
e.preventDefault ? e.preventDefault() : e.returnValue = false;
var eTarget = e.target || e.srcElement;
var clickedListItem = closest(eTarget, function(el) {
return el.tagName === 'A';
});
if(!clickedListItem) {
return;
}
var clickedGallery = clickedListItem.parentNode;
var childNodes = clickedListItem.parentNode.childNodes,
numChildNodes = childNodes.length,
nodeIndex = 0,
index;
for (var i = 0; i < numChildNodes; i++) {
if(childNodes[i].nodeType !== 1) {
continue;
}
if(childNodes[i] === clickedListItem) {
index = nodeIndex;
break;
}
nodeIndex++;
}
if(index >= 0) {
openPhotoSwipe( index, clickedGallery );
}
return false;
};
var photoswipeParseHash = function() {
var hash = window.location.hash.substring(1),
params = {};
if(hash.length < 5) { // pid=1
return params;
}
var vars = hash.split('&');
for (var i = 0; i < vars.length; i++) {
if(!vars[i]) {
continue;
}
var pair = vars[i].split('=');
if(pair.length < 2) {
continue;
}
params[pair[0]] = pair[1];
}
if(params.gid) {
params.gid = parseInt(params.gid, 10);
}
return params;
};
var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) {
var pswpElement = document.querySelectorAll('.pswp')[0],
gallery,
options,
items;
items = parseThumbnailElements(galleryElement);
// define options (if needed)
options = {
//ここからオプション追加
// showHideOpacity: true,
// bgOpacity: 1,
// spacing: 0.12,
// maxSpreadZoom: 2,
// loop: true,
// pinchToClose: true,
// closeOnScroll: true,
// closeOnVerticalDrag: true,
// preload: [1,1],
//ここまでオプション追加
galleryUID: galleryElement.getAttribute('data-pswp-uid'),
getThumbBoundsFn: function(index) {
// See Options->getThumbBoundsFn section of docs for more info
var thumbnail = items[index].el.children[0],
pageYScroll = window.pageYOffset || document.documentElement.scrollTop,
rect = thumbnail.getBoundingClientRect();
return {x:rect.left, y:rect.top + pageYScroll, w:rect.width};
},
addCaptionHTMLFn: function(item, captionEl, isFake) {
if(!item.title) {
captionEl.children[0].innerText = '';
return false;
}
captionEl.children[0].innerHTML = item.title + '<br/><small>Photo: ' + item.author + '</small>';
return true;
}
};
if(fromURL) {
if(options.galleryPIDs) {
// parse real index when custom PIDs are used
// http://photoswipe.com/documentation/faq.html#custom-pid-in-url
for(var j = 0; j < items.length; j++) {
if(items[j].pid == index) {
options.index = j;
break;
}
}
} else {
options.index = parseInt(index, 10) - 1;
}
} else {
options.index = parseInt(index, 10);
}
// exit if index not found
if( isNaN(options.index) ) {
return;
}
if(disableAnimation) {
options.showAnimationDuration = 0;
}
// Pass data to PhotoSwipe and initialize it
gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
// see: http://photoswipe.com/documentation/responsive-images.html
var realViewportWidth,
useLargeImages = false,
firstResize = true,
imageSrcWillChange;
gallery.listen('beforeResize', function() {
var dpiRatio = window.devicePixelRatio ? window.devicePixelRatio : 1;
dpiRatio = Math.min(dpiRatio, 2.5);
realViewportWidth = gallery.viewportSize.x * dpiRatio;
if(realViewportWidth >= 1200 || (!gallery.likelyTouchDevice && realViewportWidth > 800) || screen.width > 1200 ) {
if(!useLargeImages) {
useLargeImages = true;
imageSrcWillChange = true;
}
} else {
if(useLargeImages) {
useLargeImages = false;
imageSrcWillChange = true;
}
}
if(imageSrcWillChange && !firstResize) {
gallery.invalidateCurrItems();
}
if(firstResize) {
firstResize = false;
}
imageSrcWillChange = false;
});
gallery.listen('gettingData', function(index, item) {
if( useLargeImages ) {
item.src = item.o.src;
item.w = item.o.w;
item.h = item.o.h;
} else {
item.src = item.m.src;
item.w = item.m.w;
item.h = item.m.h;
}
});
gallery.init();
};
// select all gallery elements
var galleryElements = document.querySelectorAll( gallerySelector );
for(var i = 0, l = galleryElements.length; i < l; i++) {
galleryElements[i].setAttribute('data-pswp-uid', i+1);
galleryElements[i].onclick = onThumbnailsClick;
}
// Parse URL and open gallery if it contains #&pid=3&gid=1
var hashData = photoswipeParseHash();
if(hashData.pid && hashData.gid) {
openPhotoSwipe( hashData.pid, galleryElements[ hashData.gid - 1 ], true, true );
}
};
initPhotoSwipeFromDOM('.photoswipe_gallery');
})();
Also see: Tab Triggers