32 lines
910 B
JavaScript
32 lines
910 B
JavaScript
jQuery(document).ready(function($) {
|
|
|
|
const btn = $('#cstt-scroll-top');
|
|
if (!btn.length) return;
|
|
|
|
// Устанавливаем класс позиции
|
|
btn.addClass('cstt-' + csttData.position);
|
|
|
|
// Устанавливаем изображение
|
|
const icon = btn.find('.cstt-icon');
|
|
if (csttData.custom_img) {
|
|
icon.css('background-image', `url(${csttData.custom_img})`);
|
|
} else {
|
|
icon.css('background-image', `url(${csttData.default_img})`);
|
|
}
|
|
|
|
// Показываем/скрываем кнопку
|
|
$(window).on('scroll', function() {
|
|
if ($(this).scrollTop() > 400) {
|
|
btn.addClass('show');
|
|
} else {
|
|
btn.removeClass('show');
|
|
}
|
|
});
|
|
|
|
// Клик → наверх
|
|
btn.on('click', function(e) {
|
|
e.preventDefault();
|
|
$('html, body').animate({scrollTop: 0}, 500);
|
|
});
|
|
|
|
}); |