html 弧形显示文字,实现文字平滑弯曲弧形效果的插件-arctext.js

本文介绍了如何使用arctext.js插件轻松创建文字沿扇形拱桥状弯曲的效果,适用于需要动态调整文字拱形分布的情况。通过引入jQuery和arctext.js,设置参数如radius、rotate等,可以自动计算每个文字的旋转角度并应用CSS3变形,实现平滑的弧形文字展示。文章还提到了FitText.js用于动态调整字体大小。
摘要由CSDN通过智能技术生成

7c0b086c8670

扇形的文字

有时候产品大佬就是很任性,说做一个宣传页,一个类似拱门的效果,每次文字不一样,但是文字得呈现拱形状,类似上图啦。

尝试自己使用canvas画和css3的rotate旋转div,两种方法都是计算旋转角度的时候很麻烦,因为可能5个字10个字,但是得均匀地呈拱形分布,要知道让每个文字都沿着弯曲路径排布相当的复杂,于是便发现了这个好用的插件---arctext.js

它能够自动计算每个文字正确的旋转角度,并且生成对应的CSS ,其实就是基于css3和jquery,使用起来也很方便。

1.创建一个容器装文字

文字弯曲效果类似扇形拱桥状

2.引入jquery和arctext.js

3.调用arctext的方法:

$(function(){

$("#title").show().arctext({

radius:180

})

})

arctext参数说明:

radius:弯曲度数,最小的值是文字长度,如果设置为-1,则显示直线。

rotate:默认true,为false则不旋转文字

dir:默认1 (1:向下弯曲 非1(-1,0,2等):向上弯曲 )

fitText:默认false,如果你想尝试使用fitText插件,设置为true,记住包装的标签需要fluid布局。

效果图完整demo:

#title{

font-size: 20px;

color: #ffe400;

text-align: center;

}

文字弯曲效果类似扇形拱桥状

$(function(){

$("#title").arctext({

radius:180

})

})

jquery.arctext.js

/**

* Arctext.js

* A jQuery plugin for curved text

* http://www.codrops.com

*

* Copyright 2011, Pedro Botelho / Codrops

* Free to use under the MIT license.

*

* Date: Mon Jan 23 2012

*/

(function( $, undefined ) {

/*!

* FitText.js 1.0

*

* Copyright 2011, Dave Rupert http://daverupert.com

* Released under the WTFPL license

* http://sam.zoy.org/wtfpl/

*

* Date: Thu May 05 14:23:00 2011 -0600

*/

$.fn.fitText = function( kompressor, options ) {

var settings = {

'minFontSize' : Number.NEGATIVE_INFINITY,

'maxFontSize' : Number.POSITIVE_INFINITY

};

return this.each(function() {

var $this = $(this); // store the object

var compressor = kompressor || 1; // set the compressor

if ( options ) {

$.extend( settings, options );

}

// Resizer() resizes items based on the object width divided by the compressor * 10

var resizer = function () {

$this.css('font-size', Math.max(Math.min($this.width() / (compressor*10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize)));

};

// Call once to set.

resizer();

// Call on resize. Opera debounces their resize by default.

$(window).resize(resizer);

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值