クリック可能なリンクを使用してウェブページ全体のフォントサイズを増減したい。私はリンクをHTMLに入れていますが、私は物事のjQuery側に苦労しています。click()メソッドを使用してウェブページのテキストサイズを増減する
HTML
$(document).ready(function() {
$('#linkIncrease').click(function() {
modifyFontSize('increase');
});
$('#linkDecrease').click(function() {
modifyFontSize('decrease');
});
function modifyFontSize(flag) {
var divElement = $('.body');
var currentFontSize = parseInt(divElement.css('font-size'));
if (flag == 'increase') currentFontSize += 3;
else if (flag == 'decrease') currentFontSize -= 3;
else currentFontSize = 16;
divElement.css('font-size', currentFontSize);
}
});
* {
margin: auto;
padding: 0;
}
body {
margin: auto;
padding: 0;
width: 100%;
background-color: #d2eaf2;
overflow: scroll;
overflow-x: hidden;
font-family: 'Century Gothic', serif;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div> Font-Size:
<a id="linkIncrease" href="#">Increase</a>
<a id="linkDecrease" href="#">Decrease</a>
<a id="linkReset" href="#">Reset</a>
</div>
任意の助けいただければ幸いです。非常に不満を感じる!
これはあなたがタイプミス 'VAR divElement = $( '体を。')持って –
素晴らしい問題であり;'べき余分な提案:html要素のfont-sizeを代わりに変更し、remを使ってすべてのフォントサイズをスタイルすると、font-sizeの増減に合わせて縮尺が変更されます(var divElement = $( 'body'); ' –
) ! 1rem =現在のhtmlのフォントサイズ – webdevdani