我正在使用lettering.js在字符串中的每个字母周围包装<span>
元素。我正在使用PHP获取字符串。在下面的例子中,$bellcurve
还没有定义 - 这个例子就是我想我可以找到解决方案的方法,但我不确定这是否是正确的方式(但这是问题)。PHP + CSS + Lettering.js创建曲线文本
所以考虑到:
$string = "Hey!! Don't be an apple!"
我要计数的字符在该字符串,然后为每个角色,创建一个类声明,如下图所示,与“顶”每个值从而全面钟形状。
我的PHP知识使我这个远:
$string = "Hey!! Don't be an apple!";
$string = str_split($string);
$i = 1;
foreach($string as $char){
echo '.char' . $i . '{top: ' . $bellcurve * $i . 'px}';
$i++;
}
例如,快试试这个手工做看起来是这样的:
span.char1 {top: 20px}
span.char2 {top: 18px}
span.char3 {top: 16px}
span.char4 {top: 15px}
span.char5 {top: 14px}
span.char6 {top: 13px}
span.char7 {top: 12px}
span.char8 {top: 11px}
span.char9 {top: 10px}
span.char10 {top: 10px}
span.char11 {top: 10px}
span.char12 {top: 9px}
span.char13 {top: 9px}
span.char14 {top: 10px}
span.char15 {top: 10px}
span.char16 {top: 10px}
span.char17 {top: 11px}
span.char18 {top: 12px}
span.char19 {top: 13px}
span.char20 {top: 14px}
span.char21 {top: 15px}
span.char22 {top: 16px}
span.char23 {top: 18px}
span.char24 {top: 20px}
我需要知道如何做的是创造当乘以$ i(字符索引)时,系数($bellcurve
)将在遍历字符总数时创建钟形曲线。
或者如果有更好的方法,请让我知道!
谢谢!
下面是答案转换从javascript传送给PHP:
<?php
$string = get('character_slogan');
$string = str_split($string);
$count = count($string);
$pi = pi();
$c = 1.0;
$b = $count/2;
$piece = sqrt(2*$pi);
$a = 1/($c*$piece);
?>
<style type="text/css">
<?php
$x = 1;
foreach($string as $char){
$E = M_E;
$bellcurve = ($a*$E)-(pow($x-$b, 2)/pow(2*$c, 2));
echo '.char' . $x . '{top: ' . -$bellcurve . 'px}
';
$x++;
}
?>
</style>
你有什么问题?计数字符?为他们添加跨度? – Wrikken 2012-01-12 23:27:50
完成后提供链接 - 我不知道它是什么样的!这并不难,但我现在太懒惰了:P – v01pe 2012-01-12 23:45:19
@wrikken我已经澄清了一些问题 – 2012-01-13 00:49:01