【发布时间】:2014-05-02 17:30:11
【问题描述】:
我有新闻网站。我想要放置用户增加和减少页面字体大小的按钮 我在 Css 中设置默认文本大小这样
<style>
* {
font-size: 12px ;
}
</style>
和 HTML 代码
<div>
<p class="myp">The following script can be used to allow visitors to increase or decrease the size of text on your page. This can be useful for visitors who have trouble reading smaller text and allows them to increase it to something they can view more easily.</p>
</div>
<a href="#" class="increaseFont">increaseFont</a>
<a href="#" class="decreaseFont">decreaseFont</a>
<script>
$(document).ready(function () {
// Reset Font Size
var originalFontSize = $('html').css('font-size');
$(".resetFont").click(function () {
$('html').css('font-size', originalFontSize);
});
// Increase Font Size
$(".increaseFont").click(function () {
var currentFontSize = $('html').css('font-size');
var currentFontSizeNum = parseFloat(currentFontSize, 10);
$('html').css('font-size', 0);
var newFontSize = currentFontSizeNum * 1.2;
$('html').css('font-size', newFontSize);
return false;
});
// Decrease Font Size
$(".decreaseFont").click(function () {
var currentFontSize = $('html').css('font-size');
var currentFontSizeNum = parseFloat(currentFontSize, 10);
var newFontSize = currentFontSizeNum * 0.8;
$('html').css('font-size', newFontSize);
return false;
});
});
</script>
但不工作。但是当删除 Css 代码文本工作正常。请帮我。谢谢大家。
【问题讨论】:
标签: jquery asp.net-mvc