【问题标题】:Resizing font with animation, jquery用动画调整字体大小,jquery
【发布时间】:2019-04-07 23:06:27
【问题描述】:

当您阅读此问题的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);
        })
    }

字体变小的功能与上面的功能相反。

【问题讨论】:

  • 你的var s = $("#fontce").css('fontSize') 是16px 但.animate({ "fontSize": 可能需要整数值。
  • @Smollet777 你说得对,我修复了使用 parseInt 的问题(不知道它是否像那样工作)但仍然无法正常工作

标签: jquery html fonts jquery-animate


【解决方案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>

【讨论】:

  • 一切都很好,除了将字体恢复正常的 Pocetna() 方法。
  • @VL4DiMiRG 它必须做什么?
  • 将字体恢复正常。默认字体大小为 16 像素。当您按下该按钮时,它会将字体大小变为 16 像素。我发现解决方案有点复杂,也许是我不了解所有需要的东西..但很好.. tnx 寻求帮助和切片的想法
猜你喜欢
  • 1970-01-01
  • 2014-04-04
  • 2013-11-02
  • 2014-06-20
  • 1970-01-01
  • 2018-10-15
  • 1970-01-01
  • 1970-01-01
  • 2013-12-06
相关资源
最近更新 更多