今日は50のjQueryコードスニペットをAddy Osmaniからご紹介します。
if ($.browser.msie) {
// Internet Explorer is a sadist.
}
IEだけに関数を適用させることが出来ます。
jQuery.preloadImages = function() { for(var i = 0; i').attr('src', arguments[i]); } };
// Usage $.preloadImages('image1.gif', '/path/to/image2.png', 'some/image3.jpg');
画像をプレロードさせる関数$.preloadImagesを定義します。
jQuery.fn.autoscroll = function(selector) {
$('html,body').animate(
{scrollTop: $(selector).offset().top},
500
);
}
//Then to scroll to the class/area you wish to get to like this:
$('.area_name').autoscroll();
ページを自動でスクロールさせる関数です。ページトップに戻るボタンなんかに使えますね。
var tog = false; // or true if they are checked on load
$('a').click(function() {
$("input[type=checkbox]").attr("checked",!tog);
tog = !tog;
});
ページ上のチェックボックスのチェックを一度に切り替え。
全てみたい方は以下のリンクからどうぞ。
50 jQuery Snippets That Will Help You Become A Better JavaScript Developer | AddyOsmani.com | Where Web Businesses Grow
