讓卷軸自動捲到最底下的方法:
var $element = jQuery('#myElement');
$element.animate({
scrollTop: $element[0].scrollHeight
}, 300);
var $element = jQuery('#myElement');
$element.animate({
scrollTop: $element[0].scrollHeight
}, 300);
The script tag method for cross-domain data fetching: JSON with Padding, or simply JSONP. - Bob IppolitoJSONP也就是JSON with Padding,意思就是讓JSON資料添加了一些添加物(也就是function name),主要用來解決跨域資源存取的問題,用JSONP抓到的資料並不是JSON,而是一段javascript function並包含了JSON資料的程式碼,瀏覽器在取得後不是使用JSON解析器而使用JavaScript執譯器執行並得到結果。
如果你不了解Pinterest,可以參考Inside Harlequin的文章
var naturalWidth = $("#my_id")[0].naturalWidth;
var naturalHeight = $("#my_id")[0].naturalHeight;
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<dl>
<dt id="term-1">term 1</dt>
<dd>definition 1-a</dd>
<dd>definition 1-b</dd>
<dd>definition 1-c</dd>
<dd>definition 1-d</dd>
<dt id="term-2">term 2</dt>
<dd>definition 2-a</dd>
<dd>definition 2-b</dd>
<dd>definition 2-c</dd>
<dt id="term-3">term 3</dt>
<dd>definition 3-a</dd>
<dd>definition 3-b</dd>
</dl>
</body>
</html>
$("#term-2").nextUntil().css("background-color", "#ff3333");
$("#term-2").nextUntil("#term-3").css("background-color", "#ff3333");
$("#term-2").nextUntil().css("background-color", "#ff3333");
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<dl>
<dt id="term-1">term 1</dt>
<dd>definition 1-a</dd>
<dd>definition 1-b</dd>
<dd>definition 1-c</dd>
<dd>definition 1-d</dd>
<dt id="term-2">term 2</dt>
<dd>definition 2-a</dd>
<dd>definition 2-b</dd>
<dd>definition 2-c</dd>
<dt id="term-3">term 3</dt>
<dd>definition 3-a</dd>
<dd>definition 3-b</dd>
</dl>
</body>
</html>
$("#term-1").parentsUntil().css("border", '1px solid #ff6633')
$("#term-1").parentsUntil("body").css("border", '1px solid #ff6633')
$("div").data('key', 'value');
$.data(document.body, 'key', 'value');
插件需求 : jQuery & jQuery UI
相容性 : All Modern Browsers
官方網站 : http://ipicture.justmybit.com/
下載點 : http://ipicture.justmybit.com/download.php
$( "#iPicture" ).iPicture({
animation: true,
animationBg: "bgblack",
animationType: "ltr-slide",
pictures: ["picture1"],
button: "moreblack",
moreInfos:{"picture1":[{"id":"tooltip1","descr":"語文學習中心","top":"119px","left":"428px"},..}]},
// 開啟/關閉編輯模式
//modify: true,
initialize: false
});
http://padolsey.net/p/Sonic/repo/demo/demo.html
<!doctype html>
<meta charset="utf-8" />
<title>Sonic</title>
<style>
</style>
<body>
<script src="../src/sonic.js"></script>
<script>
var square = new Sonic({
width: 100,
height: 100,
fillColor: '#000',
path: [
['line', 10, 10, 90, 10],
['line', 90, 10, 90, 90],
['line', 90, 90, 10, 90],
['line', 10, 90, 10, 10]
]
});
square.play();
document.body.appendChild(square.canvas);
</script>
</body>
var circle = new Sonic({
width: 50,
height: 50,
padding: 50,
strokeColor: '#000',
pointDistance: .01,
stepsPerFrame: 3,
trailLength: .7,
step: 'fader',
setup: function() {
this._.lineWidth = 5;
},
path: [
['arc', 25, 25, 25, 0, 360]
]
});
circle.play();
document.body.appendChild(circle.canvas);
$.fn.imagesLoaded = function(callback){
var elems = this.filter('img'),
len = elems.length,
blank = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
elems.bind('load.imgloaded',function(){
if (--len <= 0 && this.src !== blank){
elems.unbind('load.imgloaded');
callback.call(elems,this);
}
}).each(function(){
// cached images don't fire load sometimes, so we reset src.
if (this.complete || this.complete === undefined){
var src = this.src;
// data uri bypasses webkit log warning (thx doug jones)
this.src = blank;
this.src = src;
}
});
return this;
};
Base64是一種使用64基的位置計數法。它使用2的最大次方來代表僅可列印的ASCII 字元。這使它可用來作為電子郵件的傳輸編碼。在Base64中的變數使用字元A-Z、a-z和0-9 ,這樣共有62個字元,用來作為開始的64個數字,最後兩個用來作為數字的符號在不同的系統中而不同。
$('#my-container').imagesLoaded( function( $images, $proper, $broken ) {
// callback provides three arguments:
// $images: the jQuery object with all images
// $proper: the jQuery object with properly loaded images
// $broken: the jQuery object with broken images
// `this` is a jQuery object of container
console.log( $images.length + ' images total have been loaded in ' + this );
console.log( $proper.length + ' properly loaded images' );
console.log( $broken.length + ' broken images' );
});
<body>
<div class="wrap">
<img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiy7FTlB5bSSvupxU0BJ8nGe9jOP5YMLfyD_m_i88W9QC3G4atjy1qMuo5J-Nyk5TgzLGJZocLt9xR139ObeKz98zsdjWzX8KJyPr2Z4PUIewqHi4frJ9xNd_9mhdaMbq9aOve6_OqNO9tX/s1600/finish_line_970825.jpg" />
<img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiy7FTlB5bSSvupxU0BJ8nGe9jOP5YMLfyD_m_i88W9QC3G4atjy1qMuo5J-Nyk5TgzLGJZocLt9xR139ObeKz98zsdjWzX8KJyPr2Z4PUIewqHi4frJ9xNd_9mhdaMbq9aOve6_OqNO9tX/s1600/finish_line_970825.jpg" />
<img src="http://2.bp.blog" />
</div>
</body>
3 images total have been loaded in [object Object]
2 properly loaded images
1 broken images
$(".wrap img").each(function(){
$(this).imagesLoaded(function(){
console.log('loaded!!');
});
});
loaded!!
loaded!!
http://mustache.github.com
http://code.jquery.com/jquery-1.7.2.min.js
https://github.com/janl/mustache.js/blob/master/mustache.js
// 範例一
var sample1 = "";
sample1 += 'Hello {{name}}';
sample1 += 'You have just won ${{value}}!';
var data1 = {
name : "Chris",
value : 10000,
}
var result1 = $.mustache(sample1, data1);
console.log(result1);
Hello Chris
You have just won $10000!
// 範例二 ture/false 判斷
var sample2 = "";
sample2 += 'Hello {{name}}';
sample2 += 'You have just won ${{value}}!';
sample2 += '{{#in_ca}}';
sample2 += 'Well, ${{taxed_value}}, after taxes.';
sample2 += '{{/in_ca}}';
var data2 = {
name : "Chris",
value : 10000,
taxed_value : 10000 - (10000 * 0.4),
in_ca : true
}
var result2 = $.mustache(sample2, data2);
console.log(result2);
Hello Chris
You have just won $10000!
Well, $6000.0, after taxes.
// 範例三 啟用/禁止Mustache編碼機制
var sample3 = "";
sample3 += '{{name}}';
sample3 += '{{age}}';
sample3 += '{{company}}';
sample3 += '{{{company}}}';
sample3 += '{{&company}}';
var data3 = {
name : "Chris",
company : "<b>GitHub</b>"
}
var result3 = $.mustache(sample3, data3);
console.log(result3);
* Chris
*
* <b>GitHub</b>
* <b>GitHub</b>
// 範例四 Non-Empty List
var sample4 = "";
sample4 += '{{#repo}}';
sample4 += '{{name}}';
sample4 += '{{/repo}}';
var data4 = {
repo: [
{ name: "resque" },
{ name: "hub" },
{ name: "rip" },
]
}
var result4 = $.mustache(sample4, data4);
console.log(result4);
<b>resque</b>
<b>hub</b>
<b>rip</b>
// 範例五 使用Lambda
// 甚麼是 Lambda? http://stackoverflow.com/questions/16501/what-is-a-lambda-function
var sample5 = "";
sample5 += '{{#wrapped}}';
sample5 += ' {{name}}';
sample5 += '{{/wrapped}}';
var data5 = {
name: "Willy",
wrapped: function() {
return function(text) {
return "" + text + ""
}
}
}
var result5 = $.mustache(sample5, data5);
console.log(result5);
<b>Willy is awesome.</b>
// 範例六 Empty List Catch
var sample6 = "";
sample6 += '{{#repo}}';
sample6 += '{{name}}';
sample6 += '{{/repo}}';
sample6 += '{{^repo}}';
sample6 += 'No repos :(';
sample6 += '{{/repo}}';
var data6 = {
repo: [
]
}
var result6 = $.mustache(sample6, data6);
console.log(result6);
No repos :(
<!DOCTYPE html>
<html>
<head>
<style>
div { color:blue; }
span { color:red; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div>
The values stored were
<span></span>
and
<span></span>
</div>
<script>var div = $("div")[0];
jQuery.data(div, "test", { first: 16, last: "pizza!" });
$("span:first").text(jQuery.data(div, "test").first);
$("span:last").text(jQuery.data(div, "test").last);</script>
</body>
</html>
$("div").data("test", { first: 16, last: "pizza!" });
$("div").data("test").first //16;
$("div").data("test").last //pizza!;
// Simple object
var myObject = {myProperty : 'myValue'};
// using jQuery append property
$.data(myObject, 'newProperty1', 'newValue1');
$.data(myObject, 'newProperty2', 'newValue2');