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.
#app
.Carousel
.lightbox(
v-show="lightboxActive"
@click.self="lightboxActive=false; currLightboxImg = currImgIdx"
)
img(:src="imgList[currLightboxImg].src")
.prev(@click="goToImg(currLightboxImg-1)")
.next(@click="goToImg(currLightboxImg+1)")
img.currImg(
:src="imgList[currImgIdx].src"
@click="lightboxActive=true"
)
transition-group.CROP(
:name="transition_name"
tag="div"
)
.Carousel_chunk(
v-for="(chunk,i) in arrChunk"
v-show="currSlide == i"
:key="i"
)
//- :style=`width:${(100/chunkSize).toFixed(1)}%;`
.chunk_item(
v-for="(item,j) in chunk"
:key="j"
@click="currImgIdx = j+(i*chunkSize)"
:class="{CURR: item.src == imgList[currImgIdx].src}"
)
img(
:src="item.src"
)
.Carousel-controls
//- button(@click="prev()") « СЮДА
svg(
@click="prev",
width='48', height='48', viewBox='0 0 24 24',
fill='gold', stroke='currentColor',
stroke-width='2', stroke-linecap='round', stroke-linejoin='round'
)
circle(cx='12', cy='12', r='10')
polyline(points='12 8 8 12 12 16')
line(x1='16', y1='12', x2='8', y2='12')
.Carousel-controls_dot(
v-for="(dot, i) in arrChunk"
:class="{CURR : currSlide == i}"
@click="goToChunk(i)"
) {{i+1}}
//- button(@click="next()") ТУДА »
svg(
@click="next",
width='48', height='48', viewBox='0 0 24 24',
fill='gold', stroke='currentColor',
stroke-width='2', stroke-linecap='round', stroke-linejoin='round'
)
circle(cx='12', cy='12', r='10')
polyline(points='12 16 16 12 12 8')
line(x1='8', y1='12', x2='16', y2='12')
*
margin 0
padding 0
box-sizing border-box
#app
display flex
height 100vh
.CROP
height 96px
overflow hidden
width 100%
padding 8px 0
// background #EEE
.Carousel
margin auto
width 480px
&_chunk
display flex
// justify-content center
justify-content space-between
align-items center
.currImg
cursor pointer
.chunk_item
// flex 1
height 80px
margin 2px
padding 2px
border 1px solid transparent
cursor pointer
&:hover
border 1px solid #2196f3
&.CURR
background gold
outline 2px solid #000
border-color transparent
img
display inline-block
height 100%
$W = 1.2rem
$H = 1.2rem
.Carousel
&-controls
user-select none
display flex
justify-content space-between
align-items center
&_dot,
svg
cursor pointer
svg:hover
fill yellow
&-controls_dot
border-radius: 50%
width $W
line-height $H
text-align center
background-color #222 //rgba(#000, .3)
font-family sans-serif
font-size .5em
color #FFF
&:hover
// background-color #2196f3
transform scale(1.4, 1.4)
&.CURR
cursor none
background-color gold//#477dca
color #000
font-weight bold
transform scale(1.4, 1.4)
.slide_next-enter-active,
// .slide_next-leave-active,
.slide_prev-enter-active,
// .slide_prev-leave-active
transition: transform .3s //cubic-bezier(0.47, 0, 1,-0.96); //ease-out
// opacity .5
.slide_next-enter,
// .slide_prev-leave-to
transform: translateX(100%)
// .slide_next-leave-to,
.slide_prev-enter
transform: translateX(-100%)
.lightbox
cursor pointer
user-select none
position fixed
z-index 1
top: 0;
left: 0;
width 100%
height 100%
//background //rgba(#000, .7)
background #616574 url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 10 10' fill='none' stroke-linecap='round' stroke-linejoin='round' stroke='gold'><line x1='4' y1='4' x2='6' y2='6' /><line x1='6' y1='4' x2='4' y2='6' /></svg>") top right no-repeat
display flex
img
cursor default
margin auto
//width: auto
max-width: 90%
max-height: 100%
.prev
.next
position absolute
top 50%
width 40px
height 60px
margin -30px 4% 0
background #444 url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' fill='none' stroke-linecap='round' stroke-linejoin='round'><path stroke='gold' d='M6,2 L4,5 L6,8'/></svg>") center / cover no-repeat
&:hover
background-color #222
.next
right 0
background-image url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' fill='none' stroke-linecap='round' stroke-linejoin='round'><path stroke='gold' d='M4,2 L6,5 L4,8'/></svg>")
const imgList = Array.from({length:33},(v,i) => ({src: `//raw.githubusercontent.com/codrops/HoverEffectIdeas/master/img/${i+1}.jpg`}))
const vm = new Vue({
el: "#app",
data() {
return {
chunkSize: 4,
imgList: imgList,
currSlide: 0,
currImgIdx: 15,
transition_name: "slide_next",
lightboxActive: false,
currLightboxImg: 15
}
},
watch: {
currImgIdx(newVal) {
this.currLightboxImg = newVal
}
},
computed: {
arrChunk() {
return Array
.from({ length: Math.ceil(this.imgList.length / this.chunkSize) }, (v, i) =>
this.imgList.slice(i * this.chunkSize, i * this.chunkSize + this.chunkSize)
);
}
},
methods: {
prev() {
this.transition_name = "slide_prev";
this.currSlide = this.currSlide == 0 ? this.arrChunk.length - 1 : this.currSlide-1;
},
next() {
this.transition_name = "slide_next";
this.currSlide = this.currSlide == this.arrChunk.length - 1 ? 0 : this.currSlide+1;
},
goToImg(n) {
this.currLightboxImg = n<0 ? this.imgList.length-1 : n%this.imgList.length;
},
goToChunk(idx) {
this.transition_name = (idx < this.currSlide) ? "slide_prev" : "slide_next";
this.currSlide = idx;
}
}
});
Also see: Tab Triggers