olidStateEveryday - Ajax,javascript,UIサンプルとチュートリアル -

Ajax,Javascriptサンプル、画像表示系の設置方法

  1. Home>
  2. 画像表示>
  3. 画像エフェクト(アクション)>
  4. 画像に角度や回転を加える

画像エフェクト(アクション)mRotate.js,mootools

画像に角度や回転を加える

  • del.icio.us に登録
  • ライブドアクリップに追加
  • Google Bookmarks に追加
  • はてなブックマークに追加
  • Yahoo!ブックマークに登録
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>mRotate</title>
  <script src="js/mootools.1.2.1.js" type="text/javascript"></script>  
  <script src="js/mRotate.js" type="text/javascript"></script>
	<!--[if IE]>
  <script src="js/excanvas.js" type="text/javascript"></script>
  <![endif]-->
  <script type="text/javascript">
  document.addEvent('domready', function () {
    $('image').rotate(-90);
    $('image2').rotate(30);
    var rot = $('image3').rotate({maxAngle:180, minAngle:-180,
  			bind:
  				[
  					{"mouseenter":function(){rot.rotateAnimation(180);}},
  					{"mouseleave":function(){rot.rotateAnimation(-180);}}
  				]
  	});     
  });  
  </script>
  <style type="text/css">
    body {
      background-color:#000;
      color:#000;
      font-family:"Trebuchet MS", Arial, sans-serif;
      font-size:14px;
    }
    .div {
      float:left;
      text-align:center;
      width:50px;
    }
  </style>
  </head>
  
  <body>
  <div style="width:665px;">  
    <div class="div">
      <img id="image3" src="image3.png" alt="" />
    </div>
    <div class="div">
      <img id="image" src="image1.jpg" alt="" />
    </div>
    
    <div class="div">
    <img id="image2" src="image2.jpg" alt="" />
    </div>
  </div>

  </body>
</html>

画像を角度をつけて表示したり、マウスアクションで回転させたりできるスクリプト。
mootoolsライブラリを使用する。
使いどころがポイント。
サンプルではあえて重ねてみたが、こういった使い方は無難なのかもしれない。  

ダウンロード

サイトから、mRotateをダウンロード。
スクリプトは3つある。

<head>~</head>の設定

<script src="js/mootools.1.2.1.js" type="text/javascript"></script> 
<script src="js/mRotate.js" type="text/javascript"></script> 
<!--[if IE]> 
<script src="js/excanvas.js" type="text/javascript"></script> 
<![endif]-->

基本的には、mootoolsとmRotateを読み込ませ、IE対策としてexcanvasも設定する。
それから、画像の角度などを設定する。

<script type="text/javascript"> 
 document.addEvent('domready', function () { $('image').rotate(-90); $('image2').rotate({angle:65}); var rot = $('image3').rotate({maxAngle:180, minAngle:-180,
bind:
[
{"mouseenter":function(){rot.rotateAnimation(180);}},
{"mouseleave":function(){rot.rotateAnimation(-180);}} ]
}); }); </script> 

imageは後で画像に設定するid、rotateの数値は角度を表す。
angleは削除しても動いた。
角度をつけて表示するときは、上記の設定で事足りる。
マウスアクションで回転させるには、image3の設定を行う。  maxAngleは最大角度、minAngleは最小角度。
mouseenterでマウスオーバーしたときに180°まで回転し、
mouseleaveでマウスアウトしたときに-180°まで回転させる設定。

<img>の設定

<img id="image" src="image.jpg" alt="" />

imgはidを設定するだけなので、簡単だ。
imgはブラウザ表示時には以下のようになる。

<span><canvas width="465" height="465"></canvas></span>

cssでの設定はあきらめた方が良いかもしれない。

関連スクリプト

感想

使いどころが難しそう。
いちいちidで設定してやるので、めんどくさそう。
でも楽しそう。
回転効果は目立たない所に設定しておいて、ふとしたときにアクションさせるとインパクトあっていいんじゃないかと思う。
アイコンとかに設定したいな。 

スクリプトの使用について

SolidStateEverydayでご紹介しているAjax,Javascript等のスクリプトをご利用になる場合は、必ず製作元のサイトで使用ライセンスを確認してください。ご利用は自己責任でお願い致します。

結局、エックスサーバーなんですよね。