简体   繁体   English

字体大小更改问题

[英]Font-Size Change Problems

I have a header which changes size on scroll within my website I am coding. 我有一个标头,该标头会在我正在编码的网站中更改滚动条的大小。 However I need to change the font size of the text within the header. 但是,我需要更改标题内文本的字体大小。 I am able to get it to go smaller with the following code. 我可以使用以下代码将其缩小。 Below that I have the relvant CSS. 在此之下,我有相对的CSS。

 $(document).on('scroll', function(e) { var value = $(this).scrollTop(); if ( value < 100 ) $("header").css("height", "100px"); else $("header").css("height", "55px"); $('h1').css({'font-size' : '30px'}); }); 
That makes it go smaller just until you refresh 这会使它变小直到您刷新

 h1 { font-size: 75px; width: 100vw; color: #212121; padding-top: 2vh; font-family: 'Raleway', sans-serif; padding-left: 1vw; font-weight: 300; z-index: 30; } 

Though if I try to make it so it resets to it's original fontsize (code below) when you scroll back up it messes up the JS and none of the JS on the page works. 尽管如果我尝试制作它,以便在您向上滚动时将其重置为原始字体大小(下面的代码),则会弄乱JS,并且页面上的所有JS均不起作用。

 $(document).on('scroll', function(e) { var value = $(this).scrollTop(); if ( value < 100 ) $("header").css("height", "100px"); $('h1').css({'font-size' : '75px'}); else $("header").css("height", "55px"); $('h1').css({'font-size' : '30px'}); }); 

if you use JS and not CoffeeScript, you need add quotes if { ... } else { ... } 如果您使用JS而不是CoffeeScript, if { ... } else { ... } ,则需要添加引号

running example https://jsfiddle.net/pmgy9ar2/ 运行示例https://jsfiddle.net/pmgy9ar2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM