Hello!
Add the below code in Settings -> Advanced -> Code Injection > FOOTER
<script>
window.addEventListener("scroll", function() {
var siteTitle = document.querySelector("#site-title");
if(window.pageYOffset >= 30) {
siteTitle.className = "smaller-font";
} else {
siteTitle.className = "";
}
});
</script>
And the below code in Design -> Custom CSS
#site-title.smaller-font {
font-size : 23px;
}