const [productLink, setProductLink] = React.useState<string>('/1')
let slides: any = []
React.useEffect(() => {
let swiperSlides = document.querySelectorAll('.heroSlide')
slides = Array.from(swiperSlides)
})
onSlideChangeTransitionStart={() => {
const active = slides.find((item: any) => item.classList.contains('swiper-slide-active'))
const arr = active.getAttribute('data-href')
setProductLink(arr)
}}
import styled, { createGlobalStyle } from 'styled-components'
import RobotoRegular from '../fonts/Roboto-Regular.ttf'
import UbuntuRegular from '../fonts/Ubuntu-Regular.ttf'
export const GlobalStyle = createGlobalStyle`
@font-face {
font-family: 'UbuntuRegular';
src: url(${UbuntuRegular}) format('truetype');
font-weight: normal;
font-style: normal;
font-display: auto;
}
@font-face {
font-family: 'RobotoRegular';
src: url(${RobotoRegular}) format('truetype');
font-weight: normal;
font-style: normal;
font-display: auto;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'UbuntuRegular';
}
li {
list-style: none;
}
a {
text-decoration: none;
}
`
declare module '*.eot'
declare module '*.woff'
declare module '*.ttf'
const anchors = document.querySelectorAll('a[href*="#"]');
for (let anchor of anchors) {
anchor.addEventListener("click", function (e) {
e.preventDefault();
burger.classList.remove("header-burger--active");
document.body.classList.remove("active");
menu.classList.remove("active");
const blockID = anchor.getAttribute("href").substr(1);
const element = document.getElementById(blockID);
const topPos = element.getBoundingClientRect().top + window.pageYOffset;
window.scrollTo({
top: topPos,
behavior: "smooth",
});
});
}
const element = document.querySelector('#element')
const topPos = element.getBoundingClientRect().top + window.pageYOffset
window.scrollTo({
top: topPos, // scroll so that the element is at the top of the view
behavior: 'smooth' // smooth scroll
})
и все тоже самое
Может это можно сделать как-то через деструктуризацию в styled-components?