• ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:animateを使用したマウスオーバー時の反応)

animateを使用したマウスオーバー時の反応

このQ&Aのポイント
  • jQuery初心者の方がanimateを使用してマウスオーバー時の反応を実現する方法について教えてください。
  • 質問者はtop_odaiクラス内のリンクを探して、そのBOX全体がリンクになるようにしたいと考えています。
  • 現在のコードでは全ての.top_odaiクラスに反応してしまうため、1つのリンクに触れた時にそれに対応するBOXのみ動作させる方法についてアドバイスをお願いします。

質問者が選んだベストアンサー

  • ベストアンサー
  • fujillin
  • ベストアンサー率61% (1594/2576)
回答No.1

>1つのリンクに触れると、他の段の全てのBOXが同じく動いてしまいます。 ホバーした要素に関係なく、全体の $('div.title a') などに対して処理をしているからでしょう。 $('div.title a', this)などでセレクトすればよいのでは?  . セレクタの指定方法について調べてみるのがよろしいかと思います。 おせっかいながら、各要素の構成が決まっているのであれば… 例えば、img要素が一つだけなのでわざわざクラス設定などをしなくともセレクト可能だし他の要素も同様なので、外側の構成要素さえ特定できれば充分と思われます。

watermusic333
質問者

お礼

ご教授ありがとうございます!!! $('div.title a', this)という形で各要素を指定しなおしたら 無事リンク1個1個で動作致しました。 imgや他要素もクラス設定なしでまとめて記載した所、こちらも問題なく動作しました。 今一度、セレクタの指定方法を勉強しなおします。 本当にありがとうございました!

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • jquery:animate中にイベントを付与

    #box{width:100%;height:100%;position:relative;} #idou{width:3000px;height:100%;position:absolute;} #ugoku{position:absolute;top:-300px;right:-1500px;} a{display:block;width:100px;height:100px;right:0;top:100px;} <div id="box"><div id="idou"><img id="ugoku" src="*.gif" width="300" height="300"><a href="">左に移動</a></div></div> ・jQuery(1.7.1) ・mousewheel.jsを使用、var scrollInt=100;$('html').mousewheel(function(event,mov){$("html,body").css("left","-="+(scrollInt*mov)+"px");});で通常は横移動するソース。 ・$("a").click(function(){$("#idou").animate({left:0},"slow");});でリンクをクリックすると左に戻す。この時の#ugokuが問題。 ・移動の角度は50度で設定、#idouのleftが-1000~-1500pxの間というような特定の間に#ugokuの画像を画面の右上から左下にanimateで流したい。 最後の項目をやろうとして完全に行き詰ってしまって困っています。 どちらかというと数学の問題かもしれません。 animate動作中に、#idouのleftが~pxになったときを拾うようなイベントは存在するのでしょうか?その他良いやり方やURLあれば教えて頂けると幸いです。 よろしくご教授ください。

  • jQuery マウスオーバーのたびに処理を繰り返す

    よろしくお願いします。 jQueryを使用して、「サムネイルにマウスを乗せると別のDiv内に大きい画像とtitle属性のテキストを表示させる」というものを作ろうとしています。 別のDiv要素には上下左右中央に画像を表示させたいと思い、見よう見まねで下記のようなコードを作成したのですが、表示される画像がサムネイル時の大きさに縮小されてしまい、元の大きさの画像として表示されません。(サムネイルには元画像をcssで縮小して表示しています) やりたいことは以下の2つです。 ・Div要素には元画像の大きさで表示させたい。 ・できれば、フェードイン・アウトで画像を切り替えたい。 色々調べてみたのですが行き詰ってしまい、こちらに質問させて頂きました。 お分かりになる方がいらっしゃいましたら、お知恵をお貸し頂けませんでしょうか。 ////スクリプト//// $(function(){ $('#contents li a').click(function(){ return false; }); $('#contents li a').mouseover(function(){ var $title = $(this).children('img').attr('title'); var w = $(this).children('img').width(); var h = $(this).children('img').height(); $('#photo img').attr('src',$(this).attr("href")); $('#photo span').text($title); var mtop = (h/2)*(-1); var mleft = (w/2)*(-1); $('#photo img').css({"width": + w + "px" ,"height": + h + "px" , "top": "50%" , "left": "50%" , "margin-top": + mtop + "px" , "margin-left": + mleft+ "px"}); }); }); ////HTML//// <div id="contents"> <ul> <li><a href="1.jpg"><img src="1.jpg" title="あああああああああああああああ" /></a></li> <li><a href="2.jpg"><img src="2.jpg" title="いいいいいいいいいいいいいいい" /></a></li> <li><a href="3.jpg"><img src="3.jpg" title="ううううううううううううううう" /></a></li> </ul> </div> <div id="photo"> <img src="1.jpg" /> <span>テキストテキスト</span> </div>

  • CSSでのマウスオーバーの画像切り替えについて

    現在横型のメニューをCSSで作成しています。 配置はうまく出来たのですが、ロールオーバーがうまくいきません。 マウスオーバーしても画像が切り替わりません。 CSSの記述をどのようにすればいいでしょうか? 以下ソース ◇HTML <body> <div id = "wrap"> <div class = "header"> <div id = "h_wrap"> </div> <div id = "u_wrap"> <ul id="hnavi"> <li id="hnavili1"><a href="#"><img src="img/top-menu-1.gif" width="149" height="60"></a></li> <li id="hnavili2"><img src="img/top-menu-2.gif" width="150" height="60"></li> <li id="hnavili3"><img src="img/top-menu-3.gif" width="151" height="60"></li> <li id="hnavili4"><img src="img/top-menu-4.gif" width="149" height="60"></li> <li id="hnavili5"><img src="img/top-menu-5.gif" width="150" height="60"></li> <li id="hnavili6"><img src="img/top-menu-6.gif" width="151" height="60"></li> </ul> </div> </div><!-- /header --> <div class = "topwrap"> topimg </div><!-- /topwrap --> <div id = "inner"> <div = "mainwrap"> mainwrap </div><!-- /mainwrap --> <div = "sidewrap"> sidewrap </div><!-- /sidewrap --> <div class = "clear"><hr /></div> </div><!-- /inner --> <div id = "footer"> footer </div><!-- /footer --> </div><!-- /wrap --> </body> ◇CSS body {text-align:center;} #wrap {width:900px; margin:0 auto; text-align:left; } .header {height:130px; } .topwrap {height: 300px;} #inner { margin:0 10px; } #mainwrap {width:690px; float:left; } #sidewrap {width:170px; float:right;} .clear {clear: both;} .clear hr {display: none;} .footer {height:118px;} /*----------------------------------------------------- headder ---------------------------------------------------- */ #h_wrap {height: 80px;} #u_wrap { height: 60px; margin: 0; padding: 0; } #hnavi { margin: 0; padding: 0; } #hnavili1 { display: inline; list-style:none; float: left; margin: 0; padding: 0; } #hnavili1 a:hover {background-image : url(../img/top-menu-1o.gif); background-position : left top; } .hnavili2 { display: inline; list-style:none; float: left; margin: 0; padding: 0; } #hnavili2 a:hover {background-image : url(../img/top-menu-1o.gif); background-position : left top; } .hnavili3 { display: inline; list-style:none; float: left; margin: 0; padding: 0; } #hnavili3 a:hover {background-image : url(../img/top-menu-1o.gif); background-position : left top; } .hnavili4 { display: inline; list-style:none; float: left; margin: 0; padding: 0; } #hnavili4 a:hover {background-image : url(../img/top-menu-1o.gif); background-position : left top; } .hnavili5 { display: inline; list-style:none; float: left; margin: 0; padding: 0; } #hnavili5 a:hover {background-image : url(../img/top-menu-1o.gif); background-position : left top; } .hnavili6 { display: inline; list-style:none; float: left; margin: 0; padding: 0; } #hnavili6 a:hover {background-image : url(../img/top-menu-1o.gif); background-position : left top; } 宜しくお願いします。

  • firefoxでfloatの調整の仕方CSS

    CSSで下記(div)のなかにBOXを3つ並べました、 ie6以上では思い通りに表示されるのですがFireFox(バージョン3.5.3)では一番右端にくるBOXが左端のBOXの下に入ってしまいます。 どなたか解決策を教えていただけますでしょうか? ----ソース部分--- <div class="setbox1"> <div id="rent1"><a href="eee.html"><img src="img/trans_rent.gif" width="234" height="69" /></a></div> <div id="rent2"><a href="aaa.html"><img src="img/trans_rent.gif" width="234" height="69" /></a></div> <div id="rent3"><a href="ccc.html"><img src="img/trans_rent.gif" width="234" height="69" /></a></div> </div> ----以下CSS---- .setbox1{ margin-left : 25px; width : 750px; } #rent1{ margin-top : 20px; margin-left : 0px; float : left; width : 234px; } #rent1 a{ background-image : url(img/rent1.gif); display : block; line-height : 0px; background-repeat : no-repeat; width : 234px; height : 69px; } #rent1 a:hover{ background-position : left bottom; } #rent1 img{border-width : 0px 0px 0px 0px; } #rent2{ margin-left : 0px; float : left; margin-right : 22px; padding-left : 22px; width : 234px; margin-top : 20px; } #rent2 a{ background-image : url(img/rent2.gif); display : block; background-repeat : no-repeat; line-height : 0px; width : 234px; height : 69px; } #rent2 a:hover{ background-position : left bottom; } #rent2 img{border-width : 0px 0px 0px 0px; } #rent3{ margin-top : 20px; margin-left : 0px; padding-left : 0px; } #rent3 a{ background-image : url(img/rent3.gif); line-height : 0px; background-repeat : no-repeat; width : 234px; height : 69px; display : block; } #rent3 a:hover{ background-position : left bottom; } #rent3 img{border-width : 0px 0px 0px 0px; }

  • HP製作でオーバーマウスがうまくいきません。

    現在、Webサイトを製作中なのですが CSSでのオーバーマウスの動作がうまくいきません。 コードは以下の通りなのですが イメージとしては、添付画像の様にA,Bのような画像で作ったボタンがあり そこのボタンにカーソルを合わせると Aのようにボタンの色が変化し 尚且つ、説明欄にAの説明が表示されるようにというイメージなのです。 しかし、実際のところは動作をせず・・・という状態です。 コードで説明しますとはセレクト、ブログ、コンタクトと何項目かあるんですが その場合は一番下のコンタクトしか動作しない状態なのです。 他はリンクタグすら正常に動きません。 思考錯誤をしていたところ  各所にある<ul class="menu">を削除したところ レイアウトは崩れるのですが 動作はしてくれました。 その部分をどのように修正すればいいのか もしくは、もっと根本的な部分から修正が必要なのか お手上げ状態です、ご助言をお願い致します。 contact.png >これがメニュー側で contact_un.png >これが説明側に表示されるべき画像です。 <html> <head> <meta content="text/html; charset=Shift_JIS" http-equiv="content-type"> <title>タイトル</title> <style type="text/css"> BODY { background-image:url(min.png); background-position: center center; background-repeat: no-repeat; background-attachment: fixed; } img { border-style:none; } .menu { padding-top:200px; /*--重ならない程度に押し下げています。--*/ } .menu a span { /*--オンマウスで表れる場所---*/ display:none; /*--最初は隠す。これがキモ。 検索エンジンに嫌われる理由でもある---*/ padding:5px; } .menu a:link{ /*--文字色 マウスを乗せたくなる色を---*/ } .menu a:visited{color:#000;} .menu a:hover, .menu a:visited{ /*--ここから下、%使う時はIEに注意---*/ display:block; text-decoration:none; } .menu a:hover .setumei_s { /*--オンマウスで表れる場所の指定---*/ display:block; position:absolute; /*--絶対位置・相対位置それぞれ長短あり。---*/ top:350px; left:110px; width:680px; font-weight:bold; line-height:1.5; } .menu a:hover .setumei_b { /*--オンマウスで表れる場所の指定---*/ display:block; position:absolute; /*--絶対位置・相対位置それぞれ長短あり。---*/ top:310px; left:110px; width:680px; font-weight:bold; line-height:1.5; } .menu a:hover .setumei_c { /*--オンマウスで表れる場所の指定---*/ display:block; position:absolute; /*--絶対位置・相対位置それぞれ長短あり。---*/ top:270px; left:100px; width:680px; font-weight:bold; line-height:1.5; } .menu a:hover .second { /*--オンマウスで表れる場所の指定---*/ top:600px; left:5px; width:23px; }summary_un #image a{ display:block; background:url() no-repeat; text-decoration:none;} #image a:hover{ color:orange; background:url(info_on.png) no-repeat; } </style> </head> <body style="background-color: rgb(0, 0, 0); margin-top: 0px; height: 27px; background-image: url(back.jpg);"> <!---セレクト--> <div style="position: absolute; top: -10px; left: -20px; width: 600px; height: 87px;" id="image"> <ul class="menu"> <a href="リンク"><img src="Mission.png"> <span class="setumei_m"><img src="Mission_un.png"></span></a> </ul> </div> <!---セレクト--> <!---ブログ--> <div style="position: absolute; top: 31px; left: -20px; width: 600px; height: 87px;" id="image"> <ul class="menu"> <a href="リンク/"><img src="blog.png"> <span class="setumei_b"><img src="blog_un.png"></span></a> </ul> </div> <!---ブログ--> <!---コンタクト--> <div style="position: absolute; top: 70px; left: -20px; width: 600px; height: 87px;" id="image"> <ul class="menu"> <a href="リンク"><img src="contact.png"> <span class="setumei_c"><img src="contact_un.png"></span></a> </ul> </div> <!---コンタクト--> </body> </html>

    • 締切済み
    • CSS
  • CSSでロールオーバーを作って中央揃えにしたい。

    CSSを使ってロールオーバーを作成しました。 がんばっているのですが、なかなか難しく、壁ばかりです。 なんとか、ロールオーバーは出来たのですが、その画像が左揃えになっていて、中央揃えにならないのです。 どなたか、お力をお貸しください。よろしくお願い致します。 HTML ----------------------------------- <link href="css.css" rel="stylesheet" type="text/css"> <div class="contents_box2"> <h3 class="no"><a href="info.html"><img src="contents_img2_1.jpg" alt="教室のご案内" width="215" height="53" /></a></h3> <p class="contents_text2">ああああああああああああああああああああああああああああああああああああああああああああああああ <p class="contents_text2">あああああああああああああああああああああああああああああああああああああああああああああああああああああああ <p class="contents_text2"><br /> <div class="rollover01"><a href="info.html"><img src="button2.jpg" alt="詳しくはこちら" width="172" height="29" /></a></div> <img src="contents_img2_3.jpg" width="215" height="18" /></div> -------------------- css↓↓↓ ------------- BODY { COLOR: #666666; TEXT-ALIGN: center; margin-top: 0px; font: 12px/130% "MS Pゴシック", Osaka, "ヒラギノ角ゴ Pro W3"; } IMG { BORDER-RIGHT: 0px; BORDER-TOP: 0px; VERTICAL-ALIGN: bottom; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px; margin: 0px; padding: 0px; } .contents_box2 { FLOAT: left; MARGIN: 0px 12px 0px 0px; WIDTH: 215px; TEXT-ALIGN: left; padding: 0px; background: url(contents_img2_2.jpg) repeat-y; } .contents_text2 { MARGIN: 10px 16px 0px } .contents_detail { PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; WIDTH: 215px; PADDING-TOP: 0px; TEXT-ALIGN: center } .rollover01 { width:172px; height:29px; background:url(img/button3.jpg) no-repeat center bottom; text-align: center; } .rollover01 a { display:block; width:172px; height:29px; font-size:1px; line-height:1px; outline:none; text-align: center; } .rollover01 a:hover { text-indent:-9999px; } -------------------------------------

  • CSSでマウスオーバーを作成しています。

    CSSでマウスオーバーを作成しています。 /**CSS内**/ #test { margin: 0; padding: 0; list-style-type: none; } #test li { text-indent: -9999px; width: 200px; height: 400px; margin: 0; padding: 0; background: url(aaa_ov.bmp) no-repeat -200px 0; ----- マウスオーバー時 } #test a { text-decoration: none; display: block; width: 200px; height: 400px; margin: 0; background: url(aaa.bmp) no-repeat 0 0; ----- 最初 } #test a:hover { text-decoration: none; background-color: transparent; background-image: none; } /**HTML内**/ <link rel="stylesheet" href="style.css" type="text/css" /> </HEAD> <BODY> <div align="center"> <ul id="test"> <li><a href="***.html">Home</a></li> </ul> </div> </BODY> としているのですが最初の画像も出ずうまくいきません。 画像パスも間違っていませんでした。 どのようにすればいいんでしょうか。 よろしくお願いします。

    • ベストアンサー
    • HTML
  • jQuery 2つのsetInterval

    写真と文字を組み合わせたクロスフェードで行き詰りました。 2つ質問があります。 【質問1】 1番目のテキストがフェードイン→3秒待機→1番目のテキストと 1番目の写真がフェードアウト→2番目・3番目同じ→繰り返し。 という感じにしたいのですが、下記の#text-boxの設定ですと setIntervalで5秒間隔でフェードインになるので#photo-boxとの タイミングが5秒ずれてしまいます。 これを合わせるにはどうすればよいのでしょうか? 【質問2】 下記のように、1つのdivでテキストと写真を入れると正常に動かなくなります。 それぞれ分けてdiv(#text-box,#photo-box)で囲うと動きます。 この原因はなんでしょうか? <div id="all-box"> <p class="text">1番目のテキスト</p> <p class="photo"><img src="img/01.jpg" width="500" height="200" alt="" /></p> <p class="text">2番目のテキスト</p> <p class="photo"><img src="img/02.jpg" width="500" height="200" alt="" /></p> <p class="text">3番目のテキスト</p> <p class="photo"><img src="img/03.jpg" width="500" height="200" alt="" /></p> </div> 宜しくお願いします。 $(function(){ $("#text-box .text").hide(); setInterval(function(){ $("#text-box") .find(".text:first-child") .fadeIn(1000) .delay(3000) .fadeOut(1000) .next(".text") .end() .appendTo("#text-box"); },5000); $("#photo-box .photo:gt(0)").hide(); setInterval(function(){ $("#photo-box") .find(".photo:first-child") .fadeOut(1000) .next(".photo") .fadeIn(1000) .end() .appendTo("#photo-box"); },5000); }); ■HTML <div id="all-box"> <div id="text-box"> <p class="text">1番目のテキスト</p> <p class="text">2番目のテキスト</p> <p class="text">3番目のテキスト</p> </div> <div id="photo-box"> <p class="photo"><img src="img/01.jpg" width="500" height="200" alt="" /></p> <p class="photo"><img src="img/02.jpg" width="500" height="200" alt="" /></p> <p class="photo"><img src="img/03.jpg" width="500" height="200" alt="" /></p> </div> </div> ■CSS #all-box{ position:relative; width:500px; height:200px; } #text-box,#photo-box{ width:500px; height:200px; } #text-box .text{ position:absolute; top:80px; left:0; z-index:2; } #photo-box .photo{ position:absolute; top:0; left:0; width:500px; height:200px; z-index:1; }

  • 外側のdivの高さを入れ子のdivの高さに自動的に合わせたい

    外側のdivの高さを入れ子のdivの高さに自動的に合わせたい 添付画像のようなコンテンツを作成しています。 外側のdiv(contents_box)内にcontents_imgとcontents_textのdivを配置しています。 このcontents_imgとcontents_textの高さに合わせて外側のcontents_boxも自動的に変動させたいのですが、どのようにしたら良いのでしょう? 高さをautoですとただの棒のようになってしまい、ダメでした。 どうぞよろしくお願い致します。 xhtml <div id="contents_box"> <div id="contents_img">ここに画像</div> <div id="contents_text"> ここにテキスト</div> </div> css #contents_box { height: auto; width: 805px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #333; } #contents_img { height: auto; width: 300px; margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 0px; float: left; } #contents_text { height: auto; width: 485px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 10px; float: right; text-align: justify; }

    • ベストアンサー
    • HTML
  • css 画像の一部分をリンクにしたいです

    画像の一部分だけをリンクにしたいです。 margin と width と height で指定したエリアをマウスオーバーすると、指定した部分だけ画像が変わってリンクになるという動作をさせたいのですが、うまくいきません。 最悪、画像が変わらなくても指定した部分のリンクができれば良いのですが画像全体がリンクになっているため、全体画像の上でマウスを動かしていると、リンク時のマウスカーソルになったり通常時のマウスカーソルになったりを繰り返しています。 html と css は以下のような記述をしています。 <html> <head> <style type="text/css"> div#menu a:hover { display:block; background-image:url(img/headerimg02.jpg); background-repeat:no-repeat; margin: 50px 468px 250px 50px; width:200px; height:100px; text-align:center; text-indent: -2000px; overflow: hidden; } </style> </head> <body> <div id="menu"> <a href="hoge.html"><img src="img/headerimg01.jpg" width="718" height="400"></a> </div> </body> </html>

    • ベストアンサー
    • CSS