我正在使用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