BACK-TO-TOP (Bedienelemente )

src/app/shared/components/back-to-top/templates

Demo Section

Each variation will be presented in the following section.

Default


Readme

back-to-top (component)

Description

This blueprint is based on the blueprint of Veams. The feature is a link to the top of the page, initially hidden, visible on scrolling event and hidden again when the scroll ends.


JIRA


Requirements


Installation

Installation with Veams from local machine

veams install bp absolute/filepath/to/back-to-top


Fields

back-to-top.hbs

Settings

Parameter Type Default Description
settings.backToTopClasses Boolean false Modifier classes for component
settings.backToTopContextClass String 'default' Context class of component
settings.definitionListJsOptions Object null JavaScript options object which gets stringified in the markup

Content

Parameter Type Description
content.linkHref String Set the default href of the link
content.linkAnchor String Anchor text for accessibility

JavaScript Options

The module gives you the possibility to override default JS options:

Option Type Default Description
selectors.backToTopButton String '[data-js-item="back-to-top-link"]' Element selector for back to top link
classes.visible String 'is-visible' Class setting the visibility of the component
scrollTimeout Number 2000 Timeout for hide/show component on scroll

Templates

back-to-top.hbs

<div class="c-back-to-top{{#if
		settings.backToTopContextClass}}--{{settings.backToTopContextClass}}{{else}}--default{{/if}}{{#if
		settings.backToTopClasses}} {{settings.backToTopClasses}}{{/if}}"
     data-css="c-back-to-top"
     data-js-module="back-to-top"{{#if settings.backToTopJsOptions}}
     data-js-options='{{stringify settings.backToTopJsOptions}}'{{/if}}>
	{{#wrapWith "grid__container"}}
		{{#wrapWith "grid__row" collapsed=true}}
			<div class="back-to-top__wrapper">
				<a href="{{content.linkHref}}" class="back-to-top__link" data-js-item="back-to-top-link">
					<span class="back-to-top__link-text">{{content.linkAnchor}}</span>
				</a>
			</div>
		{{/wrapWith}}
	{{/wrapWith}}
</div>

Data File

back-to-top.hjson

{
	"variations": {
		"default": {
			"docs": {
				"variationName": "Default"
			},
			"settings": {
				"backToTopContextClass": "default",
				"backToTopClasses": false
			},
			"content": {
				"linkHref": "#",
				"linkAnchor": "Nach oben"
			}
		}
	}
}

Styles

back-to-top.scss

/* ===================================================
component: back-to-top
=================================================== */

/* ---------------------------------------------------
Global Styles
--------------------------------------------------- */
[data-css="c-back-to-top"] {
	position: fixed;
	width: 100%;
	bottom: 0;
	z-index: 9998;

	@include print() {
		display: none;
	}

	// modifiers
	&.is-visible {

		.back-to-top__wrapper {
			transform: translateX(-50%) translateY(0);
			opacity: 1;

			@include bp($bp-tablet-p) {
				transform: translateY(0);
			}
		}
	}

	.back-to-top__wrapper {
		position: absolute;
		bottom: 15px;
		right: 0;
		width: 54px;
		height: 54px;
		box-shadow: 0 0 10px rgba(0, 0, 0, .3);
		transform: translateX(-50%) translateY(100%);
		opacity: 0;
		transition: transform $animation-duration-std $animation-easing-std, opacity $animation-duration-std $animation-easing-std;

		@include bp($bp-tablet-p) {
			transform: translateX(100%) translateY(0);
			right: 20px;
			bottom: 115px;
		}

		@include bp($bp-tablet-l) {
			right: 27px;
			bottom: 141px;
			padding-bottom: 0;
		}
	}

	.back-to-top__link {
		position: absolute;
		top: 0;
		left: 0;
		bottom: 0;
		right: 0;
		background-color: $color-white;
		transition: background-color $animation-duration-std $animation-easing-std;

		.no-touch & {

			&:hover {
				background-color: $color-green;

				&::before,
				&::after {
					margin-top: -5px;
				}

				&::before {
					opacity: 0;
				}

				&::after {
					opacity: 1;
				}
			}
		}

		&::before,
		&::after {
			@include pseudo();
			@include centering(hv);

			transition: margin-top $animation-duration-std $animation-easing-std, opacity $animation-duration-std $animation-easing-std;
		}

		&::before {
			@include sprites-icon-arrow-up-green100_s();

			opacity: 1;

			@include bp($bp-tablet-p) {
				@include sprites-icon-arrow-up-green100();
			}
		}

		&::after {
			@include sprites-icon-arrow-up-white_s();

			opacity: 0;

			@include bp($bp-tablet-p) {
				@include sprites-icon-arrow-up-white();
			}
		}

		@include hcm() {
			border: 1px solid #000;
			padding: 10px;
		}
	}

	.back-to-top__link-text {
		@include visuallyhidden();

		@include hcm() {
			@include visuallyvisible();

		}
	}
}

/* ---------------------------------------------------
Context: Default
--------------------------------------------------- */
.c-back-to-top--default {
}

Scripts

back-to-top.js

/**
 * Description of BackToTop.
 * Class properties and decorators are supported.
 *
 * @module BackToTop
 * @version v1.0.0
 *
 * @author Fabio Tedesco
 */

// Imports
import $ from 'jquery';
import Component from '@veams/component';
import scrollToElement from '../../../utilities/helpers/scroll-to-element';

class BackToTop extends Component {
	/**
	 * Class Properties
	 */
	$el = $(this.el);

	/**
	 * Event & subscribe handling
	 */

	// Event Handlers
	get events() {
		return {
			'{{context.EVENTS.click}} {{this.options.selectors.backToTopButton}}':
				'onBackToTopButtonClick',
			'{{context.EVENTS.mouseover}} {{this.options.selectors.backToTopButton}}':
				'onBackToTopButtonHover',
			'{{context.EVENTS.mouseout}} {{this.options.selectors.backToTopButton}}':
				'onBackToTopButtonHoverLeave',
			'{{context.EVENTS.touchstart}} {{this.options.selectors.backToTopButton}}':
				'onBackToTopButtonHover',
			'{{context.EVENTS.touchend}} {{this.options.selectors.backToTopButton}}':
				'onBackToTopButtonHoverLeave'
		};
	}

	// Subscribe Handlers
	get subscribe() {
		return {
			'{{context.EVENTS.pagescrollThrottled}}': 'onScroll'
		};
	}

	/**
	 * Event handler for click on back to top button
	 *
	 * @param {Object} [e] - Event object
	 *
	 */
	onBackToTopButtonClick(e) {
		e.preventDefault();

		scrollToElement(document.body);
	}

	/**
	 * Event handler for hover on back to top button
	 *
	 * @param {Object} [e] - Event object
	 *
	 */
	onBackToTopButtonHover(e) {
		clearTimeout(this.scrollTimeout);
	}

	/**
	 * Event handler for mouse leave on back to top button
	 *
	 * @param {Object} [e] - Event object
	 *
	 */
	onBackToTopButtonHoverLeave(e) {
		this.scrollTimeout = setTimeout(() => {
			this.$el.removeClass(this.options.classes.visible);
		}, this.options.scrollTimeout);
	}

	/**
	 * Event handler for Scroll
	 *
	 * @param {Object} [e] - Event object
	 *
	 */
	onScroll(e) {
		clearTimeout(this.scrollTimeout);

		let $height = this.context.detections.height;

		if (document.body.scrollTop > $height || document.documentElement.scrollTop > $height) {
			this.$el.addClass(this.options.classes.visible);

			this.scrollTimeout = setTimeout(() => {
				this.$el.removeClass(this.options.classes.visible);
			}, this.options.scrollTimeout);
		} else {
			this.$el.removeClass(this.options.classes.visible);
		}
	}

	/**
	 * Constructor for our class
	 *
	 * @see module.js
	 *
	 * @param {Object} obj - Object which is passed to our class
	 * @param {Object} obj.el - element which will be saved in this.el
	 * @param {Object} obj.options - options which will be passed in as JSON object
	 */
	constructor(obj) {
		let options = {
			selectors: {
				backToTopButton: '[data-js-item="back-to-top-link"]'
			},
			classes: {
				visible: 'is-visible'
			},
			scrollTimeout: 2000
		};

		super(obj, options);
	}

	/**
	 * Render class
	 */
	render() {
		return this;
	}
}

export default BackToTop;

HTML Output

Default

<div class="c-back-to-top--default" data-css="c-back-to-top" data-js-module="back-to-top">
	<div class="grid__container">
		<div class="grid__row is-collapsed">
			<div class="back-to-top__wrapper">
				<a href="#" class="back-to-top__link" data-js-item="back-to-top-link">
					<span class="back-to-top__link-text">Nach oben</span>
				</a>
			</div>
		</div>
	</div>
</div>

Wonach suchst du?