4

画像を<div>含む要素があります。その div 内に<p>、画像に関する情報を保持する要素があります。画像を含むものにカーソルを合わせて、要素<div>を表示または非表示にしたい。<p>

<div class="box">
    <img src="img/an_039_AN_diskette.jpg" width="310px" height="465px" />
    6 Pharma IT
    <p class="hoverbox">some information</p>
</div>

jQueryでこれを行う簡単な方法はありますか?

4

4 に答える 4

8

以下は、すべての画像に一致し、タグ P を持つ最初の兄弟をターゲットにします。

<script type="text/javascript">
$(document).ready(function(){
    $("div.box img").hover(
      function(){$(this).siblings("p:first").show();},
      function(){$(this).siblings("p:first").hide();}
    );
});
</script>

<div class="box">
  <img src="somefile.jpg" />
  <p>This text will toggle.</p>
</div>
于 2009-07-13T15:00:49.517 に答える
6
      $("css_selector_of_img").hover(
      function () {
        $("css_selector_of_p_element").show();
      },
      function () {
        $("css_selector_of_p_element").hide();
      }
      );

http://docs.jquery.com/Events/hoverを参照してください

于 2009-07-13T14:59:42.793 に答える
3
$('#divwithimage').hover(
       function(){$('#ptag').show();}, //shows when hovering over
       function(){$('#ptag').hide();} //Hides when hovering finished
);
于 2009-07-13T15:01:25.693 に答える
1
<div class="box">
    <img ... />
    <p class="hoverbox">Some text</p>
</div>

<script type="text/javascript">
    $('div.box img').hover(
        function() { $('div.box p.hoverbox').show(); },
        function() { $('div.box p.hoverbox').hide(); }
    );
</script>
于 2009-07-13T15:04:02.020 に答える