webかたつむり ウェブデザインを勉強中 ウェブ初心者のおぼえがき

webかたつむり

WEB制作会社のフォトグラファー

toggle 画像置換

.toggle()

  • 新しいバージョンではサポートされないメソッド。
  • jquery-migrate-1.3.0.min.jsをリンクすれば、過去のメソッドも使えるようになる。

<script src="js/jquery-2.2.3.min.js"></script>
<script src="js/jquery-migrate-1.3.0.min.js"></script>

  • toggleさせたい関数を、.toggle(function(){ここの中に}); 列挙する。

<script>

$(function(){
$('img').toggle(function(){
$(this).attr('src','img/ph02.jpg');},
function(){
$(this).attr('src','img/ph03.jpg');},
function(){
$(this).attr('src','img/ph04.jpg');},
function(){
$(this).attr('src','img/ph05.jpg');},
function(){
$(this).attr('src','img/ph01.jpg');})
});
</script> 

f:id:ohta-felica:20160523230505j:plain