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.
<header class="page-header">
HTML5 web приложение с фильтрами как в Instagram
</header>
<div id="photo-box" class="photo-box">
<div class="label">
<img src="https://ucarecdn.com/c7aeb97e-a73f-40bb-8966-45d692d6dde1/upload.png" alt="Upload icon" width="100" height="100"/>
<div>Нажмите или перетащите сюда изображение...</div>
</div>
<div id="loader" class="loader"></div>
</div>
<div class="download">
<a href="#" id="download-link" class="download-link">
Скачать изображение
</a>
</div>
<input type="file" id="file-picker" class="file-picker"/>
<div id="filters" class="filters">
<div class="preset preset_original" data-preset="original">
<span class="preset-name">Original</span>
</div>
<div class="preset preset_vintage" data-preset="vintage">
<span class="preset-name">Vintage</span>
</div>
<div class="preset preset_lomo" data-preset="lomo" class="">
<span class="preset-name">Lomo</span>
</div>
<div class="preset preset_clarity" data-preset="clarity" class="">
<span class="preset-name">Clarity</span>
</div>
<div class="preset preset_sinCity" data-preset="sinCity">
<span class="preset-name">Sin City</span>
</div>
<div class="preset preset_sunrise" data-preset="sunrise">
<span class="preset-name">Sunrise</span>
</div>
<div class="preset preset_crossProcess" data-preset="crossProcess">
<span class="preset-name">Cross Process</span>
</div>
<div class="preset preset_orangePeel" data-preset="orangePeel">
<span class="preset-name">Orange Peel</span>
</div>
<div class="preset preset_love" data-preset="love" class="Active">
<span class="preset-name">Love</span>
</div>
<div class="preset preset_grungy" data-preset="grungy">
<span class="preset-name">Grungy</span>
</div>
<div class="preset preset_jarques" data-preset="jarques">
<span class="preset-name">Jarques</span>
</div>
<div class="preset preset_pinhole" data-preset="pinhole">
<span class="preset-name">Pinhole</span>
</div>
<div class="preset preset_oldBoot" data-preset="oldBoot">
<span class="preset-name">Old Boot</span>
</div>
<div class="preset preset_glowingSun" data-preset="glowingSun">
<span class="preset-name">Glowing Sun</span>
</div>
<div class="preset preset_hazyDays" data-preset="hazyDays">
<span class="preset-name">Hazy Days</span>
</div>
<div class="preset preset_herMajesty" data-preset="herMajesty">
<span class="preset-name">Her Majesty</span>
</div>
<div class="preset preset_nostalgia" data-preset="nostalgia">
<span class="preset-name">Nostalgia</span>
</div>
<div class="preset preset_hemingway" data-preset="hemingway">
<span class="preset-name">Hemingway</span>
</div>
<div class="preset preset_concentrate" data-preset="concentrate">
<span class="preset-name">Concentrate</span>
</div>
</div>
<footer class="page-footer">
Статья: <a href="https://nikitakiselev.ru/article/html5-web-prilozhenie-s-filtrami-kak-v-instagram" target="_blank">HTML5 web приложение с фильтрами как в Instagram</a>
<script type="text/javascript" src="//yastatic.net/es5-shims/0.0.2/es5-shims.min.js" charset="utf-8"></script>
<script type="text/javascript" src="//yastatic.net/share2/share.js" charset="utf-8"></script>
<div class="ya-share2" data-services="vkontakte,facebook,odnoklassniki,moimir,gplus,twitter,pocket,viber,whatsapp" data-size="s"></div>
</footer>
@import 'https://fonts.googleapis.com/css?family=Roboto+Condensed';
body {
font-family: 'Roboto Condensed', sans-serif;
background: black;
color: white;
}
.page-header {
text-align: center;
font-size: 30px;
margin: 20px 0;
}
.page-footer {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background: #2b2b2b;
padding: 10px 0;
text-align: center;
a {
color: #0099cc;
}
}
.photo-box {
position: relative;
width: 500px;
height: 500px;
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
.photo {
display: block;
border-radius: 10px;
transform: scale(1);
transition:
transform .3s,
width .3s, height .3s;
&.dragenter {
transform: scale(.95);
}
}
.loader {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
background: rgba(0,0,0,.6);
display: none;
z-index: 10;
&:before {
position: absolute;
top: 50%;
transform: translateY(-50%);
text-align: center;
width: 100%;
content: 'Обработка...';
color: white;
display: block;
}
}
.label {
position: absolute;
width: 100%;
left: 0;
top: 50%;
text-align: center;
pointer-events: none;
user-select: none;
img {
display: inline-block;
}
}
}
.file-picker {
display: none;
}
.filters {
opacity: 0;
visibility: hidden;
width: 700px;
margin: 0 auto;
white-space: nowrap;
overflow-x: auto;
position: relative;
transition: opacity .8s;
&.active {
opacity: 1;
visibility: visible;
}
&::-webkit-scrollbar {
height: 4px;
background-color: rgba(100,100,100,0.2);
border-radius: 2px;
}
&::-webkit-scrollbar-thumb {
border-radius: 1px;
background: #fff;
box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
cursor: pointer;
}
&::-webkit-scrollbar-thumb:window-inactive {
background: #aaa;
}
.preset {
position: relative;
display: inline-block;
cursor: pointer;
color: black;
background: url(https://ucarecdn.com/8b971494-c589-4af1-ba29-4e5971dc6f18/presets.png) no-repeat top left;
margin: 10px;
width: 100px;
height: 100px;
text-align: center;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
&.active {
.preset-name {
background: rgba(255, 99, 71, 0.61);;
}
}
.preset-name {
display: block;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
color: white;
background: rgba(0, 0, 0, .6);
}
}
.preset.preset_clarity { background-position: 0 0; }
.preset.preset_concentrate { background-position: -100px 0; }
.preset.preset_crossProcess { background-position: -200px 0; }
.preset.preset_glowingSun { background-position: -300px 0; }
.preset.preset_grungy { background-position: -400px 0; }
.preset.preset_hazyDays { background-position: -500px 0; }
.preset.preset_hemingway { background-position: -600px 0; }
.preset.preset_herMajesty { background-position: -700px 0; }
.preset.preset_jarques { background-position: -800px 0; }
.preset.preset_lomo { background-position: -900px 0; }
.preset.preset_love { background-position: -1000px 0; }
.preset.preset_nostalgia { background-position: -1100px 0; }
.preset.preset_oldBoot { background-position: -1200px 0; }
.preset.preset_orangePeel { background-position: -1300px 0; }
.preset.preset_original { background-position: -1400px 0; }
.preset.preset_pinhole { background-position: -1500px 0; }
.preset.preset_sinCity { background-position: -1600px 0; }
.preset.preset_sunrise { background-position: -1700px 0; }
.preset.preset_vintage { background-position: -1800px 0; }
}
.download {
text-align: center;
margin-bottom: 10px;
height: 40px;
.download-link {
opacity: 0;
visibility: hidden;
display: inline-block;
color: white;
text-decoration: none;
background: #0099cc;
padding: 0 10px;
border-radius: 4px;
height: 40px;
line-height: 40px;
transition: opacity .4s;
&.show {
opacity: 1;
visibility: visible;
}
}
}
.ya-share2 {
display: inline-block;
margin-left: 30px;
}
// cache selectors
let $loader = $('#loader'),
$filters = $('#filters'),
$photoBox = $('#photo-box'),
$filePicker = $('#file-picker'),
$label = $photoBox.find('.label'),
$downloadLink = $('#download-link');
let currentPreset = 'original',
uploadedFileName = 'image';
// create image
let image = new Image();
let maxWidth = $photoBox.width(),
maxHeight = $photoBox.height(),
imageWidth = maxWidth,
imageHeight = maxHeight;
image.onload = function() {
let width = this.width,
height = this.height;
if (width >= maxWidth || height >= maxHeight) {
if (width > height) {
let ratio = width / maxWidth;
imageWidth = maxWidth;
imageHeight = height / ratio;
} else {
let ratio = height / maxHeight;
imageHeight = maxHeight;
imageWidth = width / ratio;
}
} else {
imageWidth = width;
imageHeight = height;
}
$label.hide();
// Show filters block
$filters.addClass('active');
// trigger first filter (Original)
$filters.find('.preset')
.first()
.trigger('click');
// find old canvas
let $oldCanvas = $photoBox.find('canvas');
// Create new canvas element and set its sizes
let $photo = $('<canvas>').addClass('photo').attr({
id: 'photo',
width: imageWidth,
height: imageHeight
}).css({
width: $oldCanvas.width() || '0px',
heigth: $oldCanvas.height() || '0px'
});
// Delete previous canvas
$oldCanvas.remove();
// append canvas to #photo-box
$photoBox.append($photo);
// get ctx and draw image
let ctx = $photo[0].getContext('2d');
ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
// Then image on canvas
// we change canvas size with animation
$photo.css({
width: imageWidth + 'px',
height: imageHeight + 'px'
});
$loader.hide();
}
function uploadFile(file) {
if (file.type.match('image/jpeg') || file.type.match('image/png')) {
$loader.show();
image.src = URL.createObjectURL(file);
uploadedFileName = file.name.split('.').shift();
} else {
alert('Поддерживаются только файлы jpg и png');
}
}
$photoBox
.on('dragenter', event => {
$(event.target).addClass('dragenter');
event.preventDefault();
})
.on('dragleave', event => {
$(event.target).removeClass('dragenter');
event.preventDefault();
})
.on('dragover', event => {
event.preventDefault();
})
.on('drop', event => {
$(event.target).removeClass('dragenter');
if (event.originalEvent.dataTransfer.files.length) {
uploadFile(event.originalEvent.dataTransfer.files[0]);
}
event.preventDefault();
})
.on('click', event => {
$filePicker.trigger('click');
});
$filePicker.on('change', event => {
if (event.target.files.length) {
uploadFile(event.target.files[0]);
}
});
$filters.on('click', '.preset', event => {
let
$this = $(event.target),
preset = $this.data('preset');
$this
.addClass('active')
.siblings()
.removeClass('active');
Caman('#photo', function() {
this.reset();
$downloadLink.removeClass('show');
currentPreset = preset;
if (preset !== 'original') {
this[preset]();
this.render();
$downloadLink.addClass('show');
}
});
event.preventDefault();
});
Caman.Event.listen("processStart", function(job) {
$loader.show();
});
Caman.Event.listen("renderFinished", function() {
$loader.hide();
});
$filters.on('mousewheel', function(event, delta) {
this.scrollLeft -= (delta * 70);
event.preventDefault();
});
$downloadLink.on('click', event => {
let link = event.target,
canvas = document.getElementById('photo');
link.href = canvas.toDataURL();
link.download = `${uploadedFileName}-${currentPreset}.png`;
});
Also see: Tab Triggers