2013年9月24日 星期二

TimelineMax background position change

用TimelineMAX來寫動畫是一件很簡單的事情 不過在寫連續的動畫圖,卻遇到了麻煩 ```javascript var tl = new TimelineMax({repeat:-1}); tl.to($('.Scroll'),0.1,{css:{'backgroundPosition':'-683px -222px'}}); tl.to($('.Scroll'),0.1,{css:{'backgroundPosition':'-693px -111px'}}); tl.to($('.Scroll'),0.1,{css:{'backgroundPosition':'-693px -0px'}}); tl.to($('.Scroll'),0.1,{css:{'backgroundPosition':'-595px -525px'}}); tl.to($('.Scroll'),0.1,{css:{'backgroundPosition':'-517px -525px'}}); ``` 如果這樣寫的時候,會發現background-position在變換的時候會由A點移動到B點, 而不是原本所預想的直接換background-position 試了很久終於想到可以用delay方式來處理就行了 所以正確的程式碼如下 ```javascript var tl = new TimelineMax({repeat:-1}); tl.to($('.Scroll'),0,{css:{'backgroundPosition':'-683px -222px'}},'+=.1'); tl.to($('.Scroll'),0,{css:{'backgroundPosition':'-693px -111px'}},'+=.1'); tl.to($('.Scroll'),0,{css:{'backgroundPosition':'-693px -0px'}},'+=.1'); tl.to($('.Scroll'),0,{css:{'backgroundPosition':'-595px -525px'}},'+=.1'); tl.to($('.Scroll'),0,{css:{'backgroundPosition':'-517px -525px'}},'+=.1'); ```

2013年6月26日 星期三

tinymce 4.0版外掛和主程式不同路徑怎麼解決

// 只要設定 window.tinymce.baseURL就能指定plugin的資料夾了 ```javascript window.tinymce.baseURL = '任意路徑' ```

2013年6月4日 星期二

simple_html_dom 轉 array

[simple_html_dom](http://simplehtmldom.sourceforge.net/)是一個很好用的 x(h)tml解析器 不過在使用上有些麻煩 所以就自己寫了將simple_html_dom轉array的function xml檔案 ```xml <orderdoc> <dochead> <docno>999XXXyyyymmdd99</docno> <docdate>2009-02-01</docdate> <parentid>999</parentid> </dochead> <doccontent> <order> <eshopid>001</eshopid> <opmode>A</opmode> <eshoporderno>200906010001</eshoporderno> <eshoporderdate>2009-02-01</eshoporderdate> <servicetype>1</servicetype> <shoppername>張小明</shoppername> <shopperphone></shopperphone> <shoppermobilphone></shoppermobilphone> <shopperemail></shopperemail> <receivername>張小明</receivername> <receiverphone></receiverphone> <receivermobilphone></receivermobilphone> <receiveremail></receiveremail> <receiveridnumber></receiveridnumber> <orderamount>2000</orderamount> <orderdetail> <productid></productid> <productname></productname> <quantity></quantity> <unit></unit> <unitprice></unitprice> </orderdetail> <shipmentdetail> <shipmentno>20000001</shipmentno> <shipdate>2009-02-01</shipdate> <returndate>2009-02-9</returndate> <lastshipment>Y</LastShipment> <shipmentamount>2000</shipmentamount> <storeid>886751</storeid> <eshoptype>04</eshoptype> </shipmentdetail> </lastshipment> </returndate> </shipdate> </shipmentno> </shipmentdetail> </order> <order> <eshopid>001</eshopid> <opmode>A</opmode> <eshoporderno>200906010002</eshoporderno> <eshoporderdate>2009-02-01</eshoporderdate> 廠商上線說明書 This Document is 7-Eleven /PIC/ Presco Confidential Page: 17 <servicetype>1</servicetype> <shoppername>林志玲</shoppername> <shopperphone></shopperphone> <shoppermobilphone></shoppermobilphone> <shopperemail></shopperemail> <receivername>林志玲</receivername> <receiverphone></receiverphone> <receivermobilphone></receivermobilphone> <receiveremail></receiveremail> <receiveridnumber></receiveridnumber> <orderamount>1200</orderamount> <orderdetail> <productid></productid> <productname></productname> <quantity></quantity> <unit></unit> <unitprice></unitprice> </orderdetail> <shipmentdetail> <shipmentno>20000002</shipmentno> <shipdate>2009-02-01</shipdate> <returndate>2009-02-9</returndate> <lastshipment>N</LastShipment> <shipmentamount>800</shipmentamount> <storeid>886750</storeid> <eshoptype>04</eshoptype> </shipmentdetail> <shipmentdetail> <shipmentno>20000003</shipmentno> <shipdate>2009-02-01</shipdate> <returndate>2009-02-9</returndate> <lastshipment>Y</LastShipment> <shipmentamount>400</shipmentamount> <storeid>886750</storeid> <eshoptype>04</eshoptype> <shipmentdetail> </lastshipment> </returndate> </shipdate> </shipmentno> </shipmentdetail> </lastshipment> </returndate> </shipdate> </shipmentno> </shipmentdetail> </order> </doccontent> </orderdoc> ``` php檔案 ```php define("DOCROOT",dirname(__FILE__)."/"); require DOCROOT."simple_html_dom.php"; function domToArray($elements) { $results = array(); foreach ($elements as $element) { if (count($element->children) > 0) { $results[$element->tag][] = domToArray($element->children); } else { $results[$element->tag] = $element->text(); } } return $results; } $root = file_get_html(DOCROOT."test.xml"); $order_doms = domToArray($root->find("Order")); print_r($order_doms); ```

2013年6月2日 星期日

php 民國年日期計算

西元年轉民國年,還要再處理日期的加減 光用php的date函數或是mktime是一件很麻煩的事情 所幸php內建了DataTime這個class來協助處理這件事情 ```php // 西元年轉民國年,並取得5天後的日期 $date = new DateTime("now"); $date->modify("+5 day"); $date->modify("-1911 year") // 由於Y為四位數,所以利用ltrim去0 echo ltrim($date->format("Y-m-d H:i:s"),"0"); // 民國年轉西元年,並取得10天前的日期 $date = new DateTime("101-01-01"); $date->modify("+5 day"); $date->modify("+1911 year") echo $date->format("Y-m-d H:i:s"); ```

2013年2月5日 星期二

tempnam修改

有時候在寫程式的時候會用到暫存檔 一般我們可能都是用PHP內建的tempnam來建立暫存檔 但有時候用到某些library時, 會去認檔案的副檔名,但內建的tempnam所產出的暫存檔副檔名皆為 .tmp 所以就自己另外寫了一個程式來替代暫存檔的產生 ```php class File { public static function tempnam($dir = NULL,$suffix = "tmp"){ $name = strtoupper($suffix)."_".md5(time().mt_rand()); if (empty($dir) == TRUE){ $dir = sys_get_temp_dir(); } $file = $dir.'/'.$name.".".$suffix; $handle = fopen($file, "w"); fclose($handle); if (realpath($file) == TRUE) { register_shutdown_function(create_function("", 'if (realpath("'.$file.'") == TRUE){unlink("'.$file.'");}')); // register_shutdown_function(array("File", 'rmtempnam'),$file); return $file; } throw new Exception(); } } // End file echo File::tempnam(NULL,"png"); // print xxxxxxx.png ```