指定した領域の中に画像を散らす

jqueryとjQueryRotateを使って、ランダムに画像を散らします。

jQueryRotateはこちらから
https://code.google.com/p/jqueryrotate/downloads/list

【動作確認済】
全てWINです。
IE7(tester)
IE8(winXP)
IE10(win7)
IE11(win8)
safari最新
chrome最新

画像サイズとが角度がランダム版

<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="jQueryRotate.js"></script>
<script type="text/javascript">
$(function(){
//配置したい画像
	Imgset = new Array();
	Imgset[0] = "img/bg_01.png";
	Imgset[1] = "img/bg_02.png";
//配置したい画像の数
	Imgn=20;
//画像を配置したい場所
	var ImgWrap = '#inBg'
//画像のサイズ
	var img_width = 100;
	var doc_width = $(ImgWrap).width();
	var doc_height= $(ImgWrap).height();

//画像を配置する
	for (i=0; i < Imgn; i++){
		n = Math.floor(Math.random()*Imgset.length);
		xpx = Math.floor(doc_width*Math.random()); 
		ypx = Math.floor(doc_height*Math.random());
		wpx = Math.floor(img_width*Math.random());
		var nowRotateClass = 'rotateClass' + i;
		var rotateAngle = Math.random()*360;
		ribon="<div style='position:absolute;left:"+ xpx +"px;top:"+ ypx +"px;'><img src='"+Imgset[n]+"' class='"+nowRotateClass+"' width='"+wpx+"'></div>";
		/*document.write(star);*/
		var selectNowRotateClass = '.' + nowRotateClass
		$(ImgWrap).append(ribon);
		$(selectNowRotateClass).rotate(rotateAngle);
	}
});
</script>

画像サイズとが角度が指定できる版

<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="jQueryRotate.js"></script>
<script type="text/javascript">
$(function(){
//配置したい画像
	Imgset = new Array();
	Imgset[0] = "img/bg_01.png";
	Imgset[1] = "img/bg_02.png";
//配置したい角度
	rotateAngle = new Array();
	rotateAngle[0] = 30;
	rotateAngle[1] = 330;
//配置したい画像の数
	Imgn=20;
//画像を配置したい場所
	var ImgWrap = '#inBg'
//配置したい画像のサイズ
	imgWidth = new Array();
	imgWidth[0] = 68;
	imgWidth[1] = 40;
	var doc_width = $(ImgWrap).width();
	var doc_height= $(ImgWrap).height();

//画像を配置する
	for (i=0; i < Imgn; i++){
		n = Math.floor(Math.random()*Imgset.length);
		n2 = Math.floor(Math.random()*rotateAngle.length);
		n3 = Math.floor(Math.random()*imgWidth.length);
		xpx = Math.floor(doc_width*Math.random()); 
		ypx = Math.floor(doc_height*Math.random());
		var nowRotateAngle = rotateAngle[n2];
		var nowImgWidth = imgWidth[n3];
		var nowRotateClass = 'rotateClass' + i;
		ribon="<div style='position:absolute;left:"+ xpx +"px;top:"+ ypx +"px;'><img src='"+Imgset[n]+"' class='"+nowRotateClass+"' width='"+nowImgWidth+"'></div>";
		/*document.write(star);*/
		var selectNowRotateClass = '.' + nowRotateClass
		$(ImgWrap).append(ribon);
		$(selectNowRotateClass).rotate(nowRotateAngle);
	}
});
</script>

ユーザーエージェントによって読み込むcssとスクリプトを変更する。

iOSとそれ以外で分岐さす例。
納期直前にバグが出ても、ある程度はリカバリできるかも(厭だけど。)

<script type="text/javascript">
	useragentcheck();
	function useragentcheck(){
		var agent = navigator.userAgent;
		if(agent.search(/iPhone/) != -1 || agent.search(/iPad/) != -1 || agent.search(/iPod/) != -1){
			require('js/custom.js');
		}else{
			loadingcss('css/noios.css');
			require('js/customnoios.js');
		}
	}

	function require(src){
		var element=document.createElement('script');
		element.type='text/javascript';
		element.src=src;
		document.getElementsByTagName('head')[0].appendChild(element);
	}

	function loadingcss(href){
		var element=document.createElement('link');
		element.rel='stylesheet';
		element.href=href;
		document.getElementsByTagName('head')[0].appendChild(element);
	}
</script>

IE8で半透明背景

IE8で半透明な背景を実装する方法。
.show など、透明度をjsなどで変更する場合、
ただcssで指定しておくだけでは、
半透明が無効になってしまう。
要素の操作後にscriptの側から改めて指定してあげなくてはいけないみたい……。
(4行目末尾のように)

	$(window).on('load resize', function(){
		var winWidth = $(window).width();
		var winHeight = $(window).height();
		$('#allWrap').css('width',winWidth).css('height',winHeight).css('opacity', .6);
	});

にょるんと追加内容が出てくるスクリプト

にょるんにょるん。

        <div id="whatsnew">
            <h2>更新履歴</h2>
            <a href="#" id="viewAll">全て見る</a>
            <dl>
                <dt> 2013.08.13 </dt>
                <dd> 更新内容更新内容</dd>
            </dl>
            <div id="whatsnewAll">
                <dl>
                    <dt> 2013.08.12 </dt>
                    <dd> 更新内容更新内容</dd>
                </dl>
            </div>
        </div>
	$(function($){
		$("#whatsnewAll").hide();
		$("#viewAll").click(function () {
			$(this).toggleClass('selected')
			$("#whatsnewAll").slideToggle("slow");
			if($(this).hasClass('selected')){
				$(this).text('閉じる');
				return false
			}else{
				$(this).text('全て見る');
				return false
			}
		});
	});

IEでも画像をlabelタグでクリックしたい

普通はjquery.syg_imageradioとか使えばいいのですが、
画像をクリックしたいっていう特殊な事例の場合。

$(function () {
//IE Label img
        if ($.browser.msie) {
                $('label').click(function () {
                        $('#' + $(this).attr('for')).focus().click();
                });
        }
});

label img {
        cursor:pointer;
}

参考サイト
http://depthcode.com/2010/08/ie-label-img.html

jQueryでTwitter用文字数カウント

Twitter投稿用文字数カウント。

//初期状態
var textCount = $('#voteTextarea').val().length;
var endsCount = 140 - textCount;
$('#endsCount').text(endsCount);
$('#voteAllWrap').fadeIn('slow');

//こっちの記述でもいいけど
$('#voteTextarea').on('keyup',function(){
	var textCount = $('#voteTextarea').val().length;
	var endsCount = 140 - textCount;
	$('#endsCount').text(endsCount);
});

遅延動作をさせたいなら以下のプラグインを入れて、スクリプトを書き換える。
200のとこは、遅延させたいミリ秒を入れる。
http://benalman.com/projects/jquery-throttle-debounce-plugin/

//こっちだとなおいい
$('#voteTextarea').on('keyup', $.debounce(200, function(){
	var textCount = $('#voteTextarea').val().length;
	var endsCount = 140 - textCount;
	$('#endsCount').text(endsCount);
 }));

参考記事はこちら
http://ktkne.st/elab/post/2012/strcount-throttle-debounce.html

追記。
URLの文字数は短縮されるので、
予め投稿する文字数がわかってる場合は
var endsCount = 140 – textCount;
あたりの文字数を変更するといい。
例えば30文字のURLを投稿したい場合は22文字に短縮されるから、
var endsCount = 148 – textCount;
の扱いにすればいい。

ページを読み込んでからアンカーリンクを動作させたい

ページを読み込んでからアンカーリンクを動作させるためのjQuery

$(window).load(function() {
	var ahash = location.hash;
	var gotoNum = $(ahash).offset().top;
	$('html,body').animate({ scrollTop: gotoNum }, 'slow');
	return false;
});

アニメーションを最小限にする場合’slow’を0に変える(’fast’でもいいかも)

$(window).load(function() {
	var ahash = location.hash;
	var gotoNum = $(ahash).offset().top;
	$('html,body').animate({ scrollTop: gotoNum }, 0 );
	return false;
});

参考
$(document).ready()? $(window).load() の違い
http://www.softel.co.jp/blogs/tech/archives/2425

jQueryで画面をスクロールさせる時の注意点
http://less.carbonfairy.org/post/941824993

jQuery の animate の速度(動作時間)を指定する方法
http://alphasis.info/2011/05/jquery-animate-duration/

ロールオーバーで半透明

cssの場合

a:hover{
	opacity:0.6;
	-moz-opacity:0.6;
	zoom:1; /* ie 6 7 8 */
	filter: alpha(opacity=60);        /* ie 6 7 */
	-ms-filter: "alpha(opacity=60)";  /* ie 8 */
}

jQueryの場合

$(function(){
	//セレクタで指定。使わないものは.not("#hoge")
	$("#momoHeaderBack a img,.hover").not("#h1logo").hover(function(){
		$(this).fadeTo("normal", 0.6); // マウスオーバーで透明度を60%にする
	},function(){
		$(this).fadeTo("normal", 1.0); // マウスアウトで透明度を100%に戻す
	});
});

jQueryとCSS

.opacity{
	opacity:0.6;
	-moz-opacity:0.6;
	filter: alpha(opacity=60);
	-ms-filter: "alpha( opacity=60 )";
}

$(function(){
	$('a img').on({
		'mouseenter':function(){
		$(this).addClass("opacity");
	},
		'mouseleave':function(){
		$(this).removeClass("opacity");
	}
	});
});