Javascriptスライドショーの件にて現在も質問中ですが補足致します。
添付画像の緑部分に下部のサムネイル画像をロールオーバーで
表示させたいと思っております。
その際拡大表示も別途できればさらに良いです。
特にデザイン重視ではないので、簡単にサクサク動くものを希望です。
また、同一ブラウザ上に同じようなものを並べており、
頻繁に順番を入れ替えたりもしますので
緑部分をブラウザ上にて位置指定しない方が良いです。
英語も稚拙なため、日本語のわかりやすい説明頂けますと幸いです。
初心者ですがよろしくお願い致します。
No.1
- 回答日時:
<style type="text/css">
.slideShow {
position : relative;
padding-top : 128px; /* image size */
}
.slideShow a {
display : inline-block;
width : 32px; /* index image size */
height : 32px;
margin-top : 1em;
}
.slideShow a:hover img {
width : 128px;
height : 128px;
position : absolute;
top : 0;
left : 0;
}
</style>
<p class="slideShow">
<a><img src="img0.gif" alt="" width="32" height="32"></a>
<a><img src="img1.gif" alt="" width="32" height="32"></a>
<a><img src="img2.gif" alt="" width="32" height="32"></a>
<a><img src="img3.gif" alt="" width="32" height="32"></a>
<a><img src="img4.gif" alt="" width="32" height="32"></a>
<a><img src="img5.gif" alt="" width="32" height="32"></a>
</p>
background-size を使ってもいい。
冗談。
No.2
- 回答日時:
HTML5のCANVAS要素を使って
HTMLは↓<div id="slide1">----</div>のように配置する
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>CanvasSlide</title>
<style type="text/css">
</style>
<!--[if IE]><script src="/jslib/excanvas.js"></script><![endif]-->
</head>
<body>
<div id="slide1" style="text-align:center">
<div></div>
<a href="/image/azu.jpg"><img src="/image/s_azu.jpg" alt="azu" width="130px"></a>
<a href="/image/mio.jpg"><img src="/image/s_mio.jpg" alt="mio" width="130px"></a>
<a href="/image/yui.jpg"><img src="/image/s_yui.jpg" alt="yui" width="130px" ></a>
<a href="/image/mugi.jpg"><img src="/image/s_mugi.jpg" alt="mugi" width="130px"></a>
<a href="/image/ritu.jpg"><img src="/image/s_ritu.jpg" alt="ritu" width="130px" ></a>
</div>
<script type="text/javascript">
//下のように作成する(複数スライドセットがあってもOK)
var my_slide_1 = new slide_canvas(document.querySelector("#slide1"),640,480);
</script>
<body>
</html>
肝心のjavascriptはまず、
//var G_vmlCanvasManager;
function slide_canvas(cotainer,w,h){
this.thumb=cotainer.querySelectorAll("a");
this.canvas=document.createElement("canvas");
this.canvas.width=w;
this.canvas.height=h;
cotainer.querySelector("div").appendChild(this.canvas);
// if (typeof(G_vmlCanvasManager) != 'undefined')
// this.canvas = G_vmlCanvasManager.initElement(this.canvas);
this.ctx = this.canvas.getContext('2d');
this.ctx.globalAlpha = 0;
this.main_img = new Image();
//↓は初期画像いらなければ不要
this.main_img.src = "/image/mio.jpg?" + new Date().getTime();
this.main_img.addEventListener('load',this,false);
//イベント登録
for(var i=0;i<this.thumb.length;i++){
this.thumb[i].querySelector("img").addEventListener('mousemove',this,false);
this.thumb[i].querySelector("img").addEventListener('mouseout',this,false);
this.thumb[i].querySelector("img").addEventListener('click',this,false);
}
}
==続く==
No.3
- 回答日時:
==続き==
slide_canvas.prototype.handleEvent = function(event){
switch (event.type){
case 'load':
this.ctx.globalAlpha = 0;
this.fadeIn(this.main_img);
return;
case 'mousemove':
this.ctx.globalAlpha = 0;
this.main_img.src=event.target.parentNode.href+"?"+ new Date().getTime();
return;
case 'mouseout':
this.fadeOut(this.main_img);
return;
case 'click':
event.preventDefault();
return;
}
}
slide_canvas.prototype.fadeIn = function(img){
this.StopFade();
var fadeTimer = setInterval((function(that){
return function(){
if (that.ctx.globalAlpha > 0.9) {
that.globalAlpha = 1;
that.StopFade(fadeTimer);
}else that.ctx.globalAlpha += 0.1;
that.ctx.drawImage(img,0,0,that.canvas.width,that.canvas.height);
}
})(this),100);
}
slide_canvas.prototype.fadeOut = function(img){
this.StopFade();
var fadeTimer = setInterval((function(that){
return function(){
if (that.ctx.globalAlpha < 0.1) {
that.ctx.globalAlpha = 0;
that.StopFade(fadeTimer);
}else ctx.globalAlpha -= 0.1;
that.ctx.drawImage(img,0,0,that.canvas.width,that.canvas.height);
}
})(this),100);
}
slide_canvas.prototype.StopFade = function(timer){
if(timer){
clearInterval(timer);
timer=null;
}
}
これで全部。
※全角空白は半角空白になおしてね。
※「excanvas.js」でIEにも対応させようと思ったけど、
addEventListenerとhandleEventメソッドのIEのやり方がわからんかったので
やめた。IEの人はIE9を待とう(もうすぐ)
※fadeTimerという変数は、slide_canvasオブジェクトの中で、this.timer
みたく一つあればよいのかも知れない。
※window.setIntervalメソッドのハンドル関数もイベントハンドラーみたく、
かっこよくオブジェクト(THIS)を渡せないのか....
No.4
- 回答日時:
古いIE(IE6)でも動くように改造した。
<canvas>未サポートの人は「excanvas.js」が必用。しかもフェード効果無しです。
function slide_canvas(cotainer,w,h){
this.thumb=cotainer.getElementsByTagName("a");
this.canvas=document.createElement("canvas");
this.canvas.width=w;
this.canvas.height=h;
cotainer.getElementsByTagName("div")[0].appendChild(this.canvas);
if (typeof(G_vmlCanvasManager) != 'undefined')
this.canvas = G_vmlCanvasManager.initElement(this.canvas);
this.ctx = this.canvas.getContext('2d');
this.ctx.globalAlpha = 0;
this.main_img = new Image();
this.main_img.src = "/image/mio.jpg?" + new Date().getTime();
if('undefined' !== typeof window.addEventListener)
this.main_img.addEventListener('load',this,false);
else if ('undefined' !== typeof window.attachEvent)
this.main_img.attachEvent('onload',(function(that){
return function(){that.load_handle(event);}})(this));
for(var i=0;i<this.thumb.length;i++){
if('undefined' !== typeof window.addEventListener){
this.thumb[i].getElementsByTagName("img")[0].addEventListener('mousemove',this,false);
this.thumb[i].getElementsByTagName("img")[0].addEventListener('mouseout',this,false);
this.thumb[i].getElementsByTagName("img")[0].addEventListener('click',this,false);
}else if ('undefined' !== typeof window.attachEvent){
this.thumb[i].getElementsByTagName("img")[0].attachEvent('onmousemove',(function(that){
return function(){that.mousemove_handle(event);}})(this));
this.thumb[i].getElementsByTagName("img")[0].attachEvent('onmouseout',(function(that){
return function(){that.mouseout_handle(event);}})(this));
this.thumb[i].getElementsByTagName("img")[0].attachEvent('onclick',(function(that){
return function(){that.click_handle(event);}})(this));
}
}
}
==続く==
No.5
- 回答日時:
==続き==
slide_canvas.prototype.handleEvent = function(event){
switch (event.type){
case 'load':this.load_handle(event);return;
case 'mousemove':this.mousemove_handle(event);return;
case 'mouseout':this.mouseout_handle(event);return;
case 'click':this.click_handle(event);return;
}
}
slide_canvas.prototype.load_handle = function(event){
this.ctx.globalAlpha = 0;
this.fadeIn(this.main_img);
}
slide_canvas.prototype.mousemove_handle = function(event){
this.ctx.globalAlpha = 0;
var target = event.target || event.srcElement;
this.main_img.src=target.parentNode.href+"?"+ new Date().getTime();
}
slide_canvas.prototype.mouseout_handle = function(event){
this.fadeOut(this.main_img);
}
slide_canvas.prototype.click_handle = function(event){
if(window.event){
event.returnValue = false;
event.cancelBubble = true;
}else{
event.preventDefault();
}
//this.popup();
}
slide_canvas.prototype.fadeIn = function(img){
this.StopFade();
var fadeTimer = setInterval((function(that){
return function(){
if (that.ctx.globalAlpha > 0.9) {
that.globalAlpha = 1;
that.StopFade(fadeTimer);
}else that.ctx.globalAlpha += 0.1;
that.ctx.drawImage(img,0,0,that.canvas.width,that.canvas.height);
}
})(this),100);
}
slide_canvas.prototype.fadeOut = function(img){
this.StopFade();
var fadeTimer = setInterval((function(that){
return function(){
if (that.ctx.globalAlpha < 0.1) {
that.ctx.globalAlpha = 0;
that.StopFade(fadeTimer);
}else that.ctx.globalAlpha -= 0.1;
that.ctx.drawImage(img,0,0,that.canvas.width,that.canvas.height);
}
})(this),100);
}
slide_canvas.prototype.StopFade = function(timer){
if(timer){
clearInterval(timer);
timer=null;
}
}
var my_slide_1 = new slide_canvas(document.getElementById("slide1"),640,480);
終わり
※後はcanvasサイズの自動取得&リサイズ対応と、クリック時のポップアップ対応
の実装すれば、とりあえず完成。
このソースちょろっと変えれば別に<canvas>でなくてもよさげだ。
No.6
- 回答日時:
レスがないので、連続回答を勝手に続けます。
(※ポップアップとリサイズにも対応した。後、オートスクロールも機能追加すれば
使い物になるかも)
=その1=
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Test</title>
<style type="text/css">
</style>
<!--[if IE]><script src="/jslib/excanvas.js"></script><![endif]-->
</head>
<body>
<h2 style="text-align:center">Canvas Slide By HTML5 or IE(excanvas.js)</h2>
<div id="slide1">
<div></div>
<div>
<a href="/image/azu.jpg"><img src="/image/s_azu.jpg" alt="azu" width="130px"></a>
<a href="/image/mio.jpg"><img src="/image/s_mio.jpg" alt="mio" width="130px"></a>
<a href="/image/yui.jpg"><img src="/image/s_yui.jpg" alt="yui" width="130px"></a>
<a href="/image/mugi.jpg"><img src="/image/s_mugi.jpg" alt="mugi" width="130px"></a>
<a href="/image/ritu.jpg"><img src="/image/s_ritu.jpg" alt="ritu" width="130px"></a>
</div>
</div>
<script type="text/javascript">
function slide_canvas(cotainer,w,h){
//初期値のセット
this.bgcolor=document.body.style.backgroundColor;
this.cotainer=cotainer;
this.cotainer.style.textAlign="center";
this.w=w;
this.h=h;
this.thumb=cotainer.getElementsByTagName("a");
//CANVAS初期化
this.canvas=document.createElement("canvas");
this.canvas.style.border = "solid 1px gray";
this.canvas.width=this.w?this.w:Math.floor(this.cotainer.clientWidth*0.9);
this.clientHeight=this.cotainer.clientHeight;
var height=window.innerHeight||document.documentElement.clientHeight;
this.canvas.height=this.h?this.h:Math.floor((height-this.clientHeight)*0.9);
cotainer.getElementsByTagName("div")[0].appendChild(this.canvas);
//Canvasコントローラー生成
if (typeof(G_vmlCanvasManager) != 'undefined')
this.canvas = G_vmlCanvasManager.initElement(this.canvas);
this.ctx = this.canvas.getContext('2d');
this.ctx.globalAlpha = 0;
//PopUp Window初期化
this.popdiv=document.createElement("div");
this.popdiv.id="popdiv";
this.popdiv.style.border = "double 2px black";
this.popdiv.style.display="none";
this.popdiv.style.position = 'absolute';
<=続く=>
No.7
- 回答日時:
(その2)
<=続き=>
//初期画像セット
this.main_img = new Image();
this.main_img.src = "/image/mio.jpg?" + new Date().getTime();
//画像ロードイベント登録
if('undefined' !== typeof window.addEventListener)
this.main_img.addEventListener('load',this,false);
else if ('undefined' !== typeof window.attachEvent)
this.main_img.attachEvent('onload',(function(that){
return function(){that.load_handle(event);}})(this));
//サブネールのイベント登録
for(var i=0;i<this.thumb.length;i++){
if('undefined' !== typeof window.addEventListener){
this.thumb[i].getElementsByTagName("img")[0].addEventListener('mousemove',this,false);
this.thumb[i].getElementsByTagName("img")[0].addEventListener('mouseout',this,false);
this.thumb[i].getElementsByTagName("img")[0].addEventListener('click',this,false);
}else if ('undefined' !== typeof window.attachEvent){
this.thumb[i].getElementsByTagName("img")[0].attachEvent('onmousemove',(function(that){
return function(){that.mousemove_handle(event);}})(this));
this.thumb[i].getElementsByTagName("img")[0].attachEvent('onmouseout',(function(that){
return function(){that.mouseout_handle(event);}})(this));
this.thumb[i].getElementsByTagName("img")[0].attachEvent('onclick',(function(that){
return function(){that.click_handle(event);}})(this));
}
}
//Windowリサイズのイベント
if('undefined' !== typeof window.addEventListener)
window.addEventListener('resize',this,false);
else if ('undefined' !== typeof window.attachEvent)
window.attachEvent('onresize',(function(that){
return function(){that.resize_handle(event);}})(this));
//PopUp Windowのイベント
if('undefined' !== typeof window.addEventListener)
this.popdiv.addEventListener('click',this,false);
else if ('undefined' !== typeof window.attachEvent)
this.popdiv.attachEvent('onclick',(function(that){
return function(){that.click_handle(event);}})(this));
}
<=続く=>
No.8
- 回答日時:
(その3)
<=続き=>
//イベントハンドラーの振り分け(IE以外)
slide_canvas.prototype.handleEvent = function(event){
switch (event.type){
case 'load':this.load_handle(event);return;
case 'resize':this.resize_handle(event);return;
case 'mousemove':this.mousemove_handle(event);return;
case 'mouseout':this.mouseout_handle(event);return;
case 'click':this.click_handle(event);return;
}
}
//イベントハンドラーのメソッドたち
slide_canvas.prototype.load_handle = function(event){
this.ctx.globalAlpha = 0;
this.fadeIn(this.main_img);
}
slide_canvas.prototype.resize_handle = function(event){
this.canvas.width=this.w?this.w:Math.floor(this.cotainer.clientWidth*0.9);
var height=window.innerHeight||document.documentElement.clientHeight;
this.canvas.height=this.h?this.h:Math.floor((height-this.clientHeight)*0.9);
this.ctx.globalAlpha = 0;
this.fadeIn(this.main_img);
}
slide_canvas.prototype.mousemove_handle = function(event){
this.ctx.globalAlpha = 0;
var target = event.target || event.srcElement;
this.main_img.src=target.parentNode.href+"?"+ new Date().getTime();
}
slide_canvas.prototype.mouseout_handle = function(event){
this.fadeOut(this.main_img);
}
slide_canvas.prototype.click_handle = function(event){
if(window.event){
event.returnValue = false;
event.cancelBubble = true;
}else{
event.preventDefault();
}
var target = event.target || event.srcElement;
if(target.parentNode.id!="popdiv")
this.popup(this.main_img);
else this.popclose();
}
//CANVAS操作のメソッドたち
slide_canvas.prototype.fadeIn = function(img){
this.StopFade();
var fadeTimer = setInterval((function(that){
return function(){
if (that.ctx.globalAlpha > 0.9) {
that.globalAlpha = 1;
that.StopFade(fadeTimer);
}else that.ctx.globalAlpha += 0.1;
that.ctx.drawImage(img,0,0,that.canvas.width,that.canvas.height);
}
})(this),100);
}
==続くって、もういいかげんにしろってか==
No.9
- 回答日時:
(その4)
<=続き=>
slide_canvas.prototype.fadeOut = function(img){
this.StopFade();
var fadeTimer = setInterval((function(that){
return function(){
if (that.ctx.globalAlpha < 0.1) {
that.ctx.globalAlpha = 0;
that.StopFade(fadeTimer);
}else that.ctx.globalAlpha -= 0.1;
that.ctx.drawImage(img,0,0,that.canvas.width,that.canvas.height);
}
})(this),100);
}
slide_canvas.prototype.StopFade = function(timer){
if(timer){
clearInterval(timer);
timer=null;
}
}
slide_canvas.prototype.popup = function(img){
this.popdiv.appendChild(img);
document.body.appendChild(this.popdiv);
this.popdiv.style.top = (window.pageYOffset||document.documentElement.scrollTop)+50+"px";
this.popdiv.style.left = (window.pageXOffset||document.documentElement.scrollLeft)+50+"px";
this.popdiv.style.display="block";
document.body.style.backgroundColor="gray";
}
slide_canvas.prototype.popclose = function(){
document.body.removeChild(this.popdiv);
document.body.style.backgroundColor=this.bgcolor;
}
//var my_slide_1 = new slide_canvas(document.getElementById("slide1"),640,480);
var my_slide_1 = new slide_canvas(document.getElementById("slide1"));
</script>
</body>
</html>
これでおしまい。たぶん誰も見ないだろうな...
我輩にも、もっとショートコーディングの技が備わってれば、もっと短く
一回の回答で済ませられたかも。
No.10ベストアンサー
- 回答日時:
いろいろ手直しして、とりあえずの
最終形が出来たんで勝手にクローズ
ソースは↓を見てね。
(例)
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Canvas Slide By HTML5</title>
<style type="text/css">
</style>
<!--[if IE]><script type="text/javascript" src="/jslib/excanvas.js"></script><![endif]-->
<script type="text/javascript" src="/jslib/CanvasSlide.js"></script>
</head>
<body>
<h2 style="text-align:center">Canvas Slide By HTML5 or IE(excanvas.js)</h2>
<div style="text-align:center">
<button type="button" onclick="my_slide_1.slideShowInit(1000);">SlideShow Start</button>
<button type="button" onclick="my_slide_1.slideShowStop();">SlideShow Stop</button>
</div>
<div id="slide1">
<div></div>
<div>
<a href="/image/azu.jpg"><img src="/image/s_azu.jpg" alt="azu"></a>
<a href="/image/mio.jpg"><img src="/image/s_mio.jpg" alt="mio"></a>
<a href="/image/yui.jpg"><img src="/image/s_yui.jpg" alt="yui"></a>
<a href="/image/mugi.jpg"><img src="/image/s_mugi.jpg" alt="mugi"></a>
<a href="/image/ritu.jpg"><img src="/image/s_ritu.jpg" alt="ritu"></a>
</div>
</div>
<script type="text/javascript">
var my_slide_1 = new slide_canvas(document.getElementById("slide1"));
</script>
</body>
</html>
回答頂きほんとうにありがとうございます。
少し教えて頂きましたjqueryでしらべまして、簡単なサンプルをみつけましたので
そちらを使用しようと思っておりますが少し質問があります。
http://myisland.jp/template/tips/gallery/gallery …
上記のサンプルコードなのですが同一ページで複数設置して
個別に稼働することは可能でしょうか?
再度質問あげてますのでよろしければ回答いただければと思います。
またできれば、かなり簡単な説明いただければ幸いです^^;
それではよろしくお願い致します。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
似たような質問が見つかりました
- JavaScript 空白で入力フォームのボタンをクリックしたら、ブラウザの上部からjavascriptで 表示されるアラ 1 2022/05/20 11:16
- Gmail Gメールの受信トレイの表示が変わって、戸惑っています 1 2023/04/04 17:52
- AJAX 自作の地図をグーグルマップのようにしたい 3 2022/11/15 11:53
- YouTube ユーチューブへの動画投稿にサムネイルを付ける方法は? 1 2022/07/21 23:45
- その他(プログラミング・Web制作) WEBアプリ開発に必要な言語 5 2023/06/28 16:57
- Excel(エクセル) エクセル、日々の集計整理方法。(再送です。) 5 2022/10/02 00:19
- カスタマイズ(車) 初めてカーナビの取付にチャンレジします。アドバイスください。 5 2022/12/04 18:32
- C言語・C++・C# C言語初心者 構造体 課題について 2 2023/03/10 19:48
- 英語 ”be”<動詞>と<助動詞>混同の誤り ― 形式主義文法論の混迷 12 2022/05/17 11:09
- Illustrator(イラストレーター) 「頂点で線分を伸ばす」作業がうまく行かない。 1 2022/09/09 10:19
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
JQueryで画像の上で文字を動かす
-
デフォルト非表示にしたい。【t...
-
アップロードファイルの種類に...
-
jQueryでのドラッグアンドドロ...
-
画像拡大とともにエレメントも...
-
jQueryで同じクラス名のものを...
-
htmlの中のhtmlをタブで切り替え
-
複数bxsliderをタブで切り替え...
-
Javascript初心者|jQueryの.va...
-
embed要素のsrc属性の値を変更...
-
オンマウスで画像表示+表示し...
-
MAX関数を使ってからLEFT JOIN...
-
c++std::string型をTCHARに変換...
-
javascriptテキストBOX色を元に...
-
jspでcssが読み込めない
-
jsでサムネイルを拡大表示 複...
-
createElementで作成した要素を...
-
条件分岐でキーが入力されてい...
-
JSPでの画像ファイル表示
-
htmlの記述で link rel=styles...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
デフォルト非表示にしたい。【t...
-
jQueryで同じクラス名のものを...
-
Colorboxがうまく設置できません
-
Javascript初心者|jQueryの.va...
-
jQueryでのドラッグアンドドロ...
-
アップロードファイルの種類に...
-
embed要素のsrc属性の値を変更...
-
fancyboxのポップアップ時の画...
-
JQueryで画像の上で文字を動かす
-
一定時間で入れ替わるバナー画...
-
ボタンを押すたびに交互に切り...
-
全部のサイコロをjavascriptで...
-
交互に入れ替わる画像を複数配置
-
clear機能を失わずにファイルア...
-
JavaScriptが、Firefoxで動かな...
-
「画像クリックで音声再生」を ...
-
bxsliderで最初に縦に複数表示...
-
JQueryを使用して、画像をドラ...
-
イラストのボタンを押したとき...
-
背景色と連動するスライドショ...
おすすめ情報