29 lines
779 B
JavaScript
29 lines
779 B
JavaScript
import { Controller } from 'stimulus';
|
|
|
|
/*
|
|
* This is an example Stimulus controller!
|
|
*
|
|
* Any element with a data-controller="default" attribute will cause
|
|
* this controller to be executed. The name "default" comes from the filename:
|
|
* default_controller.js -> "default"
|
|
*
|
|
* Delete this file or adapt it for your use!
|
|
*/
|
|
export default class extends Controller {
|
|
connect() {
|
|
var btn = this.element;
|
|
|
|
$(window).scroll(function() {
|
|
if ($(window).scrollTop() > 300) {
|
|
btn.classList.remove('d-none')
|
|
} else {
|
|
btn.classList.add('d-none')
|
|
}
|
|
});
|
|
|
|
btn.addEventListener('click', function(e) {
|
|
$('html, body').animate({scrollTop:0}, '300');
|
|
});
|
|
}
|
|
}
|