2013-01-03 41 views
2

我想在我的新Drupal 7網站的網站名稱上使用Lettering.js。這是我迄今爲止所做的:如何在網站名稱上使用帶Drupal 7的Lettering.js?

  1. 我從Github下載了文件,並將其放在我的主題中的腳本文件夾中。 (所以它看起來像這樣/sites/all/themes/MyThemeName/scripts/jquery.lettering.js)

  2. 然後我使用這個語法「的腳本[] =腳本/ jQuery的添加腳本到我的主題的信息文件。 lettering.js」。我可以看到當我查看頁面源代碼時正在加載腳本。

我遇到問題的部分是如何調用它。我一直在閱讀文檔http://drupal.org/node/171213,但我仍然感到困惑。我假設我應該將該調用放在template.php中,並且我可以使用$ site_name來訪問網站中的網站名稱,但我不確定該從哪裏去。

感謝任何能提供一些建議的人。

回答

0

lettering.js所做的一切就是將文本分成多個區段。

<p>Hey</p> 

變爲

<p><span class="char1">H</span><span class="char2">e</span><span class="char3">y</span></p> 

詳見源代碼:

$chars = str_split($site_name); 
$letter_site_name = ""; 
for($i=0,$count=count($chars);$i<$count;$i++) { 
    $letter_site_name = '<span class="char' . ($i+1) . '">' . $chars[$i] . '</span>'; 
} 

如果:https://github.com/davatron5000/Lettering.js/blob/master/jquery.lettering.js

這可以很容易地與預處理功能,或在你的模板使用PHP完成你要使用lettering.js無論如何你必須寫一個額外的JavaScript。 這個腳本必須定義一個Drupal行爲,它可以在所有標題上用類字體標記運行letteringjs。

(function ($) { 
    Drupal.behaviors.headline_lettering = { 
    attach:function (context, settings) { 
     $("h1.lettering:not(.lettering-attached)", context) 
     .addClass('lettering-attached') 
     .lettering(); 
    } 
    } 
})(jQuery); 
0

展開上一個答案。

drupal_add_js($path_to_theme . '/scripts/jquery.lettering-0.6.1.min.js'); 

以及上述可添加額外的腳本來作爲page.tpl.php中

<script> 
(function ($) { 
    Drupal.behaviors.headline_lettering = { 
    attach:function (context, settings) { 
     $(".lettering:not(.lettering-attached)", context) 
     .addClass('lettering-attached') 
     .lettering(); 
    } 
    } 
})(jQuery); 
</script> 

我所做的:

的JavaScript可以使用drupal_add_js()中的template.php添加不要在腳本中添加.h1,然後我只需要爲任何文本添加一個「字母」類,然後將應用字體。

然後您可以使用Kern.js來調整每個字母的位置。它生成需要包含在頁面中的CSS。