首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在JavaScript悬停上显示/隐藏div

在JavaScript悬停上显示/隐藏div
EN

Stack Overflow用户
提问于 2013-12-19 11:23:22
回答 3查看 5.2K关注 0票数 0

我希望图像覆盖(与文本)只显示时,div是悬空的。默认情况下隐藏。如果合适的话由JavaScript。

我尝试复制css,给出第一个(显示:无)和第二个(悬停和不显示),但是没有工作,所以尝试使用JavaScript添加/删除(display: none)类。

我已经包括了一个实时网址。我收到了6个主页的图片。

Live:http://bit.ly/1jl1QaT

HTML

代码语言:javascript
复制
<div class="desc"><p><?=((strlen($r_main['friendlyTitle'])>40)?substr($r_main['friendlyTitle'],0,40).'...':$r_main['friendlyTitle']);?></p></div>
                </div></a>
                <a href="Shopping/"><div class="feature-2">
                    <div class="header"><p>Shopping</p></div>
                    <div class="desc"><p>Grab yourself a pair of Mink Fur Eyelashes for only £19.95 </p></div>
                </div></a>

CSS

代码语言:javascript
复制
#content-mid .col-2 .features .feature-1 .desc, #content-mid .col-2 .features .feature-2 .desc, #content-mid .col-2 .features .feature-3 .desc, #content-mid .col-2 .features .feature-4 .desc, #content-mid .col-2 .features .feature-5 .desc, #content-mid .col-2 .features .feature-6 .desc { position:absolute; width: 220px; height: 50px  zoom: 1; filter: alpha(opacity=90); opacity: 0.9; background: #333; bottom: 0; margin-bottom: 5px; display: none; }

#content-mid .col-2 .features .feature-1 .desc, #content-mid .col-2 .features .feature-2 .desc, #content-mid .col-2 .features .feature-3 .desc, #content-mid .col-2 .features .feature-4 .desc, #content-mid .col-2 .features .feature-5 .desc, #content-mid .col-2 .features .feature-6 .desc-show { position:absolute; width: 220px; height: 50px     zoom: 1; filter: alpha(opacity=90); opacity: 0.9; background: #333; bottom: 0; margin-bottom: 5px;  }

JavaScript

代码语言:javascript
复制
$(".desc").hover(
      function () {
        $(this).removeClass("desc-show");
      },
      function () {
        $(this).addClass("desc");
      }
    );
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-12-19 11:25:40

HTML

代码语言:javascript
复制
<div style="background-color:red;">
<div id="blah">DEMO TEXT ON MOUSE OVER</div>
</div>

JAVA脚本

代码语言:javascript
复制
$('#blah').hover(function() {
    $(this).fadeTo(1,1);
},function() {
    $(this).fadeTo(1,0);
});

CSS

代码语言:javascript
复制
#blah {
    width:100px;
    height:100px;
    background-color:green;
    visibility: visible;
    opacity:0;
    filter:alpha(opacity=0);
}

琴杆

票数 3
EN

Stack Overflow用户

发布于 2013-12-19 12:03:38

代码语言:javascript
复制
#content-mid .col-2 .features .feature-1{
    border: 1px solid #E5E5E5;
    float: left;
    height: 160px;
    overflow: hidden;
    padding: 5px;
    position: relative;
    width: 220px;
    z-index:-1;
}
#content-mid .col-2 .features .image_holder_home_page{
    height: 160px;
    overflow: hidden;
    position: relative;
    width: 220px;
}

#content-mid .col-2 .features .feature-1 .header{
    background: none repeat scroll 0 0 #0098FF;
    height: 30px;
    position: absolute;
    width: 95.5%;
}

请将上述css代码添加到您的站点中。因为有些潜水元素已经溢出了。这将解决这个问题。

票数 2
EN

Stack Overflow用户

发布于 2013-12-19 11:29:33

试试这把小提琴。我已经用了很多次了。

代码语言:javascript
复制
$(document).ready(function () {
                $(document).on('mouseenter', '.divbutton', function () {
                    $(this).find(":button").show();
                }).on('mouseleave', '.divbutton', function () {
                    $(this).find(":button").hide();
                });
            });

只需编辑这段代码,把你的div,而不是按钮。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20680431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档