用动画,jQuery调整字体大小

时间:2018-11-04 10:48:44

标签: jquery html fonts jquery-animate

当您阅读此问题的title时,您已经知道我想要做什么。 我已经读过有关resizing with animation的内容,但是无法解决我的问题。如果您有时间检查我的代码:

这些是我用于整个功能的按钮。 需要调整大小的文本的ID为(“ fontce”)。

<form id="forma"> <p>Големина на фонт</p> <button type="button" value="Pocetna" onclick="Pocetna()">Почетна</button> <button type="button" value="Zgolemi" onclick="Zgolemi()">Зголеми</button> <button type="button" value="Namali" onclick="Namali()">Намали</button> </form>

此功能我想将字体恢复正常。

var s = $("#fontce").css('fontSize');
function Pocetna() {
        jQuery(document).ready(function () {

            ("#fontce").animate({
            "fontSize":s
            },1000);
        });

以及使字体变大的功能:

function Zgolemi()
    {
        jQuery(document).ready(function () {
            var s1 = $(this.fontSize);
            ("#fontce").animate({
               "fontSize":s1*1.5
            },1000);
        })
    }

缩小字体的功能与上方字体相反。

1 个答案:

答案 0 :(得分:1)

let s = $("#fontce").css('fontSize').slice(0, -2);

$("#pocetna").click(Pocetna);
$("#zgolemi").click(Zgolemi);
$("#namali").click(Namali);

function Pocetna() {
  $("#fontce").animate({
    fontSize: s
  }, 1000);
}

function Zgolemi() {
  let s1 = $("#fontce").css('fontSize').slice(0, -2);
  console.log(s1)
  $("#fontce").animate({
    fontSize: s1 * 1.5
  }, 1000);
}

function Namali() {
  let s2 = $("#fontce").css('fontSize').slice(0, -2);
  console.log(s2)
  $("#fontce").animate({
    fontSize: s2 / 1.5
  }, 1000);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="forma">
    <p>Големина на фонт</p>
    <button type="button" value="Pocetna" id="pocetna">Почетна</button>
    <button type="button" value="Zgolemi" id="zgolemi">Зголеми</button>
    <button type="button" value="Namali" id="namali">Намали</button>
</form>
<p id="fontce">
    To connect to the internet, you'll need an Internet service provider (ISP)
    and some hardware:ISP. An ISP is a company that gives you access to the Internet.
    You sign up for an account with an ISP just as you do for telephone service or utilities.
    ISPs are usually phone companies( for a DSL or fiber optic connection)
    or TV providers(for cable or satellite connection).<br>
    Hardware. For a broadband connection, such as DSL, fiber optic, or cable,
    you'll need a boradband modem. This might be included as part of the start-up hardware from your ISP
    wgen you sign up for a broadband account. If you play to share Internet access with multiple PCs by
    using a home network, you'll also need a router.
</p>