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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<div id="app"></div>
body {
background-color: #333;
}
button {
z-index: 1;
position: relative;
}
.projects {
height: 100vh;
position: fixed;
width: 100%;
top: 0;
}
.project{
padding-top: 10px;
background: white;
color: black;
height: 92vh;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
box-shadow: 0px -2px 10px 1px #403838;
transform: translateX(100%);
span {
writing-mode: vertical-rl;
margin-bottom: 20px;
font-size: 18px;
line-height: 1.8;
transform: rotate(180deg);
}
}
const Data = {
projects: [
{ name: "project 1" },
{ name: "project 2" },
{ name: "project 3" },
{ name: "project 4" },
{ name: "project 5" }
]
};
const menuTl = new TimelineMax({ paused: true, reversed: true });
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
menuActive: false,
allProjects: Data.projects,
csPreviewActive: false,
activePanel: null,
openedCases: null
};
this.togglePreviewCase = this.togglePreviewCase.bind(this);
this.previewCaseReverseHandler = this.previewCaseReverseHandler.bind(this);
// store the timeline in the component because we need to access
// a callback that's inside the component in the reverse complete event
this.previewCaseTl = new TimelineMax({
paused:true,
reversed: true,
onReverseComplete: this.previewCaseReverseHandler
});
// create a master time line to animate both timeline on close
this.closeAllTl = new TimelineMax({
paused: true
})
}
componentDidMount() {
this.slideMenu();
}
closeAll = (e) => {
const { activePanel, menuActive, csPreviewActive} = this.state;
this.setState({
activePanel: null,
menuActive: false,
csPreviewActive: false
});
this.previewCaseTl.clear();
//My problem is here, I dont understand why menuTl.reverse is not triggered after the this.previewCase and need a second clikc on a menu button???
this.closeAllTl
.add(this.previewCase())
.add(menuTl.reverse())
.play();
}
// bring the project to view//
slideMenu = () => {
var projects = document.getElementsByClassName("project");
//transform the HTMLcollection to an array
var projects = Array.from(projects);
menuTl.set(".tomsah-project", { zIndex: 0 }).staggerTo(projects, 1, {
cycle: { x: ["56%","64%", "72%", "80%", "88%"] },
ease: Power2.easeInOut
});
return menuTl;
};
toggleMenu = e => {
e.preventDefault();
const {openedCases,
menuActive,
activePanel,
csPreviewActive} = this.state;
if(menuTl.reversed()) {
menuTl.play();
this.setState({csPreviewActive : true});
} else if( !menuTl.reversed() && activePanel !== null) {
this.closeAll();
} else {
menuTl.reverse();
this.previewCaseTl.clear();
this.setState({
menuActive: !menuActive
});
}
};
previewCase = (id) => {
var element = `#${id}`;
const { openedCases, allProjects} = this.state;
// transform this.refs to an array of the projects
var caseList = [];
Object.keys(this.refs).forEach((key, index) => {
//var previousCaseList = animatedList;
const ref = this.refs[key];
if(ref.id !== openedCases && ref.id !== "" ) {
caseList.push(`#${ref.id}`);
}
});
//get the index of the click element in caseList array
var idIndex = caseList.indexOf(element);
//get the length of the previous array of animated panel
if(openedCases !== null) {
var openedCasesLength = openedCases.length;
}
// create a new array of panels that need animatiom
var animatedArray = caseList.slice(openedCasesLength, idIndex + 1)
//keep track of all the previous open panel
var previousAnimatedArray = caseList.slice(0, idIndex + 1);
//reverse the panels
if( idIndex < openedCasesLength - 1) {
var reversePanels = caseList.slice(idIndex + 1, openedCasesLength)
this.previewCaseTl
.staggerTo(reversePanels, 1, {x: '+=50%', ease: Power2.easeInOut})
.reverse();
}
//stagger Method
this.previewCaseTl
.staggerTo(animatedArray, 1, {x: '-=50%', ease: Power2.easeInOut})
.play();
// set the state with the new array of animetd panel
this.setState({ openedCases: previousAnimatedArray });
};
togglePreviewCase = e => {
const { activePanel, csPreviewActive } = this.state;
const { id } = e.currentTarget;
e.preventDefault();
// first check if a panel is active
if ( activePanel ) {
// check if the id is the same of the active panel
if ( activePanel === id ) {
console.log('open the project full screen');
// the current panel is the active one, set the
// state prop to null
this.setState({ activePanel: id });
} else if ( activePanel !== id) {
// the current panel is not the active update the state with the new id
this.setState({ activePanel: id });
}
this.previewCase(id);
} else {
// there's no active panel
// set the active panel
this.setState({csPreviewActive: true});
this.setState({ activePanel: id });
// since there's no active panel the timeline is empty
// add the instances to the timeline and play it
this.previewCase(id);
}
};
// the reverse complete callback
// used to create the new instance of the panel tween
// if there's an active panel
previewCaseReverseHandler(){
const { activePanel } = this.state;
// if there's an active panel in the state, clear the timeline and
// create a new instance with the active panel
if ( activePanel ) {
this.previewCaseTl.clear();
this.previewCase(activePanel);
} else {
this.previewCaseTl.clear();
console.log('nothing to see');
}
}
render() {
const { allProjects } = this.state;
return (
<div className="main">
<button onClick={this.toggleMenu} id='toggleMenu'> menu </button>
<div className="projects" ref="projects">
{allProjects.map((project, index) => {
return (
<div
className="project"
ref={`CaseStudy${index}`}
key={index}
id={`project-${index + 1}`}
onClick={this.togglePreviewCase}
>
<span> {project.name} </span>
</div>
);
})}
</div>
</div>
);
}
}
/*
* Render the above component into the div#app
*/
ReactDOM.render(<App />, document.getElementById("app"));
Also see: Tab Triggers