我希望每个 div 在按钮悬停时显示其内容

发布于 2025-01-04 19:58:18 字数 1154 浏览 3 评论 0原文

我有 div 中的图像和段落,当您滚动标题时我希望显示该段落,这段代码适用于我的其他网站,但由于某种原因在这里不起作用

任何人都可以告诉我我做错了什么

 $(document).ready(function() {

$('.post-band h2').hover(function(){
        $(".entry p",this).fadeTo("fast", 1);
          //$(".entry p",this).slideDown();
        },
    function(){
         $(".entry p",this).fadeTo("fast", 0);
        //  $(".entry p",this).slideUp();
                });

});

<div class="post-band" id="post-67">

 <h2>Dale Rodman</h2>
<div class="band-image">
<img width="300" height="250" src="http://localhost/wp-content/uploads/2012/02/dale1.jpg" class="attachment-post-thumbnail wp-post-image" alt="dale" title="dale" /></div>

 <div class="entry">
   <p>Dale has been passionate about music ever since he stopped being passionate about something else, when he puts his mind to something there is not stopping this machine, playing guitar since he was little his ability to absorb different styles has help to create a style like non other.</p>
<h3>Acoustic Guitar, Vocals</h3>
 </div>
    </div>

I have divs which images and Paragraphs in the, when you roll over the title i want the paragraph to show, this code worked for my other site but for some reason isnt working here

Can anyone tell me what i am doing wrong

 $(document).ready(function() {

$('.post-band h2').hover(function(){
        $(".entry p",this).fadeTo("fast", 1);
          //$(".entry p",this).slideDown();
        },
    function(){
         $(".entry p",this).fadeTo("fast", 0);
        //  $(".entry p",this).slideUp();
                });

});

<div class="post-band" id="post-67">

 <h2>Dale Rodman</h2>
<div class="band-image">
<img width="300" height="250" src="http://localhost/wp-content/uploads/2012/02/dale1.jpg" class="attachment-post-thumbnail wp-post-image" alt="dale" title="dale" /></div>

 <div class="entry">
   <p>Dale has been passionate about music ever since he stopped being passionate about something else, when he puts his mind to something there is not stopping this machine, playing guitar since he was little his ability to absorb different styles has help to create a style like non other.</p>
<h3>Acoustic Guitar, Vocals</h3>
 </div>
    </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

后知后觉 2025-01-11 19:58:18

悬停函数中的 $(".entry p",this) 会查找 $('.post-band h2') 内的选择器(在 h2 内) )。您可能需要混合使用 .closest() 向上移动,然后使用 .find() 向下移动。

但发布你的 html 以获得更好的答案。

$(".entry p",this) in your hover function looks for the selector inside $('.post-band h2') (inside the h2). You probably need a mix of .closest() to go up and then .find() to go down.

But post your html to get a better answer.

宫墨修音 2025-01-11 19:58:18

这是一个可能的解决方案的小提琴:http://jsfiddle.net/sDJDr/

我使用的javascript如下也是ori上面的意思。

$(document).ready(function() {

    $('.post-band h2').hover(function(){
        var $p = $(this).closest('div.post-band').find('p');
        $p.fadeTo("fast", 1);
        //$(".entry p",this).slideDown();
    },
    function(){
        var $p = $(this).closest('div.post-band').find('p');
        $p.fadeTo("fast", 0);
        //  $(".entry p",this).slideUp();
    });

});

Here's a fiddle with a possible solution: http://jsfiddle.net/sDJDr/

The javascript I used is below and is also what ori meant above.

$(document).ready(function() {

    $('.post-band h2').hover(function(){
        var $p = $(this).closest('div.post-band').find('p');
        $p.fadeTo("fast", 1);
        //$(".entry p",this).slideDown();
    },
    function(){
        var $p = $(this).closest('div.post-band').find('p');
        $p.fadeTo("fast", 0);
        //  $(".entry p",this).slideUp();
    });

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文