主要規格是當我 focus到一個連結後底下的字樣會進行跑馬燈的效果.使用到 CSS3的 animation跟 keyframe來呈現.當然有設定文字呈現最基本的 white-space以及overflow: hidden (這樣才有跑馬燈效果阿) .
Check out this Pen!
透過 keyframes可以設定在動畫的秒數內文字的位置來做到跑馬燈效果, 算是很彈性的作法!
Check out this Pen!
var arg = 1;
function funcTest() {
alert(arg);
var arg = 2;
}
funcTest();
function funcTest2() {
alert(arg);
//var arg = 2;
}
funcTest2();
Check out this Pen!
* {background-color:grey;}
/* a=0 b=0 c=0 d=0 -> specificity = 0,0,0,0 */
li {color:blue;}
/* a=0 b=0 c=0 d=1 -> specificity = 0,0,0,1 */
li:first-line {background-color:yellow;}
/* a=0 b=0 c=0 d=2 -> specificity = 0,0,0,2 */
ul li {background-color:pink;}
/* a=0 b=0 c=0 d=2 -> specificity = 0,0,0,2 */
ul ol+li {}
/* a=0 b=0 c=0 d=3 -> specificity = 0,0,0,3 */
h1 + *[rel=up]{}
/* a=0 b=0 c=1 d=1 -> specificity = 0,0,1,1 */
ul ol li.red:first-line {background-color:red;}
/*a=0 b=0 c=1 d=4 -> specificity = 0,0,1,4 */
ul ol li.red {background-color:cyan;}
/* a=0 b=0 c=1 d=3 -> specificity = 0,0,1,3 */
li.red.level {background-color:lime;}
/* a=0 b=0 c=2 d=1 -> specificity = 0,0,2,1 */
#x34y {color:red;}
/* a=0 b=1 c=0 d=0 -> specificity = 0,1,0,0 */
Check out this Pen!
YUI().use('event-key', function (Y) {
Y.one("body").on("key", function(e){
e.preventDefault();
alert("esc press");
location.href = "http://codepen.io";
}, "esc");
});
Check out this Pen!
Check out this Pen!
Check out this Pen!
Check out this Pen!
Check out this Pen!
JavaScript 在語言本身、模擬物件導向的開發中,this 都是很清楚的代表一個 instance。
把 this 搞複雜的原因,其實是瀏覽器特有的 DOM API。
像是 DOM Event、或像是 window.XMLHttpRequest 這樣的全域方法。
this 在對應的處理函式中都不會是所預期 instance。
這也是為什麼在 Y.on 或 Y.io 都有提供設定 context 的參數。
或者得自己去使用 call 或 apply 取執行 Handler、讓 Handler 正確處理。
如果今天開發的是沒有瀏覽器的 JavaScript,例如 Node.js,
this 通常是不會造成太大的困擾的 :)
on: {
viewload: function () {
api = this;
api.get(node).
one('form').on('submit', _handleSubmit, api);
// (1).api is the context
}
}
_handleSubmit = function (event) {
var _api = this; //(2) this is api from (1) context
_api.get(node).all('input');
_enableForm.call(_api, arg1, arg2);
//(3.1) this _api is context
_enableForm.apply(_api, [arg1, arg2]);
//(3.2) this _api is context
}
上述的範例說當一個模組在頁面載入完成要執行的 function call (on viewload). 當按下 Submit 按鈕送出之後相對應的handler (_handleSubmit) 會處理相對應的動作._api.confirm(message, callback);
//callback will need _api as context
_api.confirm(message, Y.bind(callback. _api));
//callback will need _api as context
Deferred: function( func ) {
var doneList = jQuery.Callbacks( "once memory" ),
failList = jQuery.Callbacks( "once memory" ),
progressList = jQuery.Callbacks( "memory" ),
#!/bin/bash
find /home/kevin/music -type f -name "*.ogg" -exec ls -1 {} \; 2> ./log/output | sort >playlist.txt
git@github.com:miiicasa/yui3.git
git checkout git@github.com:miiicasa/yui3.git somefolder
git submodule add git@github.com:miiicasa/yui3.git somefolder
git tag -l
git checkout "v3.6.0"
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b "v3.6.0"
Check out this Pen!
<div class="content">
<div class="bd">
<div class="draw"></div>
</div>
<div class="ft">
<img src="http://avekta.com/site2/wp-content/uploads/2011/10/ico_fb.png" />
</div>
</div>Check out this Pen!
Check out this Pen!
javascript:(function() {
function get_filetype(fmt_id) {
switch(fmt_id) {
case '5':
case '6':
case '34':
case '35':
return 'FLV';
case '18':
case '22':
case '37':
case '38':
case '82':
case '83':
case '84':
case '85':
return 'MP4';
case '43':
case '44':
case '45':
case '46':
case '100':
case '101':
case '102':
return 'WEBM';
default:
return 'unknown';
}
}
function get_video_url(fmt_stream_map,
chosen_fmt_id,
avail_fmt_ids) {
fmt_stream_map=unescape(fmt_stream_map);
if(avail_fmt_ids.indexOf(chosen_fmt_id)===0)
return
fmt_stream_map.substring(4,
fmt_stream_map.indexOf('&quality='));
if(avail_fmt_ids.indexOf(chosen_fmt_id)===avail_fmt_ids.length-1)
return
fmt_stream_map.substring(fmt_stream_map.lastIndexOf('http'),
fmt_stream_map.lastIndexOf('&quality='));
var pattern=new RegExp('&itag='+avail_fmt_ids[avail_fmt_ids.indexOf(chosen_fmt_id)-1]+',url=(.+?)&quality=');
return fmt_stream_map.match(pattern)[1];
}
(function main() {
var args=yt.playerConfig['args'];
var fmt_quality_list='';
var chosen_fmt_id=0;
var fmt_info=args['fmt_list'].split(',');
var fmt_resolution='';
var avail_fmt_ids=new Array(fmt_info.length);
for(var i in fmt_info) {
avail_fmt_ids[i]=fmt_info[i].split('/')[0];
fmt_resolution=fmt_info[i].split('/')[1];
fmt_quality_list+=(avail_fmt_ids[i]+' = '+fmt_resolution+' ('+get_filetype(avail_fmt_ids[i])+')\n');
}
loop: while(true) {
chosen_fmt_id=prompt('Please enter a format id.\n'+fmt_quality_list, avail_fmt_ids[0]);
if(chosen_fmt_id===null) {
return;
}
for(var i in avail_fmt_ids) {
if(chosen_fmt_id===avail_fmt_ids[i]) {
break loop;
}
}
}
window.open(get_video_url(args['url_encoded_fmt_stream_map'], chosen_fmt_id, avail_fmt_ids)+'&title='+document.getElementsByName('title')[0].content);
}());
}());
def _closed_captions_xml_to_srt(self, xml_string):
srt = ''
texts = re.findall(r'([^<]+) ', xml_string, re.MULTILINE)
# TODO parse xml instead of regex
for n, (start, dur_tag, dur, caption) in enumerate(texts):
if not dur: dur = '4'
start = float(start)
end = start + float(dur)
start = "%02i:%02i:%02i,%03i" %(start/(60*60), start/60%60, start%60, start%1*1000)
end = "%02i:%02i:%02i,%03i" %(end/(60*60), end/60%60, end%60, end%1*1000)
caption = unescapeHTML(caption)
caption = unescapeHTML(caption) # double cycle, intentional
srt += str(n+1) + '\n'
srt += start + ' --> ' + end + '\n'
srt += caption + '\n\n'
return srt