Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                input#toggle(type="checkbox")
#new-body
	label(for="toggle") toggle theme

              
            
!

CSS

              
                html,
body {
	margin: 0;
	padding: 0;
	height: 100%;
	font-size: 18px;
	font-family: "Quicksand", sans-serif;
	font-weight: 400;
}

* {
	box-sizing: border-box;

	cursor: none;
	user-select: none;
}

////

:root {
	--transition-speed: 200ms;
	--transition-type: ease;

	--background-color: #f2f2f2;
	--text-color: #222;
	--text-color-hover: #444;
	--underline-color: var(--text-color);
	--underline-hover-color: #000;
}

#new-body {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
	background-color: var(--background-color);
}

input[type="checkbox"] {
	display: none;
}

label {
	color: var(--text-color);
	position: relative;
	transition: color var(--transition-speed) var(--transition-type);
	z-index: 0;

	&:before {
		content: "";
		position: absolute;
		height: 2px;
		width: 100%;
		background-color: var(--underline-color);
		bottom: 0;
		left: 0;
		transform: scaley(1) translatey(0);
		transform-origin: center bottom;
		transition: transform var(--transition-speed) var(--transition-type),
			color var(--transition-speed) var(--transition-type);
		z-index: -1;
	}

	&:hover {
		color: var(--text-color-hover);

		&:before {
			transform: scaley(1.5) translatey(-0.26em);
			background-color: var(--underline-hover-color);
		}
	}
}

input[type="checkbox"]:checked ~ #new-body {
	--background-color: #222;
	--text-color: #f2f2f2;
	--text-color-hover: #ddd;
	--underline-color: var(--text-color);
	--underline-hover-color: var(--text-color-hover);
}

#cursor,
.cursor {
	--width: 10px;
	--height: var(--width);
	--border-radius: var(--width);
	--positionx: 0;
	--positiony: 0;
	--offset: -5px;
	--scale: 1;
	height: var(--height);
	width: var(--width);
	border-radius: var(--border-radius);
	border: 1px solid var(--text-color);
	position: fixed;
	top: var(--offset);
	left: var(--offset);
	pointer-events: none;
	opacity: 0;
	transform: translate(var(--positionx), var(--positiony)) scale(var(--scale));
	transition: all 200ms ease-in-out, transform 100ms;

	&.active {
		--width: 60px;
		--offset: calc(var(--width) / -2);
	}

	#new-body:hover & {
		opacity: 1;
	}
}

              
            
!

JS

              
                const Cursor = (function () {
	function Cursor(props) {
		this.cursor = {
			el: undefined,
			x: null,
			y: null
		};
		this.hover = {
			elements: props.hoverElements || ["LABEL"]
		};
		this.listeners = {
			onmousemove: this.onmousemove.bind(this)
		};

		//user settings
		this.properties = {
			body: props.body || document.body,
			cursorSelector: props.cursorSelector || "#cursor",
			offset: props.offset || 0
		};
	}

	Cursor.prototype.init = function () {
		this.draw();
		this.addEventListeners();
	};

	Cursor.prototype.addEventListeners = function () {
		document.body.addEventListener("mousemove", this.listeners.onmousemove);
	};

	Cursor.prototype.onmousemove = function () {
		this.getCursorXY();
		this.appendPosition();
		this.isHover();
	};

	Cursor.prototype.getCursorXY = function () {
		(this.cursor.x = window.event.x), (this.cursor.y = window.event.y);
	};

	Cursor.prototype.appendPosition = function () {
		const offset = this.properties.offset;
		let cursorPosition = `--positionx: ${this.cursor.x - offset}px;
							  --positiony: ${this.cursor.y - offset}px;`;
		this.cursor.el.style = cursorPosition;
	};

	Cursor.prototype.isHover = function () {
		let _this = {
			x: this.cursor.x,
			y: this.cursor.y,
			tags: this.hover.elements
		};
		var elHover = {
			tagName: document.elementFromPoint(_this.x, _this.y).tagName,
			tags: _this.tags,
			isTagClickable: document.elementFromPoint(_this.x, _this.y).dataset.clickable
		};

		this.activeCursor(
			elHover.tags.includes(elHover.tagName) || elHover.isTagClickable
		);
	};

	Cursor.prototype.activeCursor = function (isActive) {
		let _this = this;
		isActive
			? _this.cursor.el.classList.add("active")
			: _this.cursor.el.classList.remove("active");
	};

	Cursor.prototype.draw = function () {
		const idSymbol = "#",
			classSymbol = ".";
		const cursorDOM = document.createElement("span");

		//if class or id
		if (this.properties.cursorSelector.includes(idSymbol)) {
			cursorDOM.id = this.properties.cursorSelector.replace(idSymbol, "");
			this.properties.body.appendChild(cursorDOM);
			this.cursor.el = document.getElementById(cursorDOM.id);
		} else if (this.properties.cursorSelector.includes(classSymbol)) {
			cursorDOM.classList.add(
				this.properties.cursorSelector.replace(classSymbol, "")
			);
			this.properties.body.appendChild(cursorDOM);
			this.cursor.el = document.querySelector(this.properties.cursorSelector);
		} else {
			return console.error(
				`cursorSelector: '${this.properties.cursorSelector}' - You need to choose if you want a class or an id`
			);
		}
	};

	return Cursor;
})();

// Init

const props = {
	body: document.getElementById("new-body"),
	cursorSelector: "#cursor",
	offset: 0,
	hoverElements: ["LABEL", "INPUT", "A", "BUTTON"]
};

const newCursor = new Cursor(props);
newCursor.init();

              
            
!
999px

Console