ドロップダウン(クリック)
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="js/dropdown.js"></script>
<script type="text/javascript" src="js/rollover.js"></script>
// テキスト
$(function () {
$('.nav-txt p').click(function() {
if ($(this).attr('class') == 'selected') {
// メニュー非表示
$(this).removeClass('selected').next('.dropdown').slideUp('fast');
} else {
// 表示メニューを閉じる
$('.nav-txt p').removeClass('selected');
$('.dropdown').hide();
// メニュー表示
$(this).addClass('selected').next('.dropdown').slideDown('fast');
}
});
// マウスカーソルがメニュー上/メニュー外
$('.nav-txt p, .dropdown').hover(function(){
over_flg = true;
}, function(){
over_flg = false;
});
// メニュー領域外をクリックでメニューを閉じる
$('body').click(function() {
if (over_flg == false) {
$('.nav-txt p').removeClass('selected');
$('.dropdown').slideUp('fast');
}
});
});
// 画像(rollover)
$(function () {
$('.nav-on img').click(function() {
if ($(this).attr('class') == 'rollover') {
// メニュー非表示
$(this).removeClass('rollover').next('.dropdown').slideUp('fast');
} else {
// 表示メニューを閉じる
$('.nav-on img').removeClass('rollover');
$('.dropdown').hide();
// メニュー表示
$(this).addClass('rollover').next('.dropdown').slideDown('fast');
}
});
// マウスカーソルがメニュー上/メニュー外
$('.nav-on img, .dropdown').hover(function(){
over_flg = true;
}, function(){
over_flg = false;
});
// メニュー領域外をクリックでメニューを閉じる
$('body').click(function() {
if (over_flg == false) {
$('.nav-on img').removeClass('rollover');
$('.dropdown').slideUp('fast');
}
});
});
// 画像(opacity)
$(function () {
$('.nav-img img').click(function() {
if ($(this).attr('class') == 'active') {
// メニュー非表示
$(this).removeClass('active').next('.dropdown').slideUp('fast');
} else {
// 表示メニューを閉じる
$('.nav-img img').removeClass('active');
$('.dropdown').hide();
// メニュー表示
$(this).addClass('active').next('.dropdown').slideDown('fast');
}
});
// マウスカーソルがメニュー上/メニュー外
$('.nav-img img, .dropdown').hover(function(){
over_flg = true;
}, function(){
over_flg = false;
});
// メニュー領域外をクリックでメニューを閉じる
$('body').click(function() {
if (over_flg == false) {
$('.nav-img img').removeClass('active');
$('.dropdown').slideUp('fast');
}
});
});
/*
Standards Compliant Rollover Script
Author : Daniel Nolan
http://www.bleedingego.co.uk/webdev.php
*/
function initRollovers() {
if (!document.getElementById) return
var aPreLoad = new Array();
var sTempSrc;
var aImages = document.getElementsByTagName('img');
for (var i = 0; i < aImages.length; i++) {
if (aImages[i].className == 'btn') {
var src = aImages[i].getAttribute('src');
var ftype = src.substring(src.lastIndexOf('.'), src.length);
var hsrc = src.replace(ftype, '_o'+ftype);
aImages[i].setAttribute('hsrc', hsrc);
aPreLoad[i] = new Image();
aPreLoad[i].src = hsrc;
aImages[i].onmouseover = function() {
sTempSrc = this.getAttribute('src');
this.setAttribute('src', this.getAttribute('hsrc'));
}
aImages[i].onmouseout = function() {
if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
this.setAttribute('src', sTempSrc);
}
}
}
}
window.onload = initRollovers;