javascript - jQuery - 文本描述悬停

标签 javascript jquery css html

我有一个显示我的一些作品(作品集)的 div 网格,我正在处理一个鼠标悬停事件,它使标题 div 向上移动并显示描述。

看看:

http://olliejones.com/demo/demo.html

现在,如您所见,当您将鼠标悬停在一个框上时,标题框的高度会向上移动,显示描述。我猜效果很好,但是描述文本(当您没有悬停时)位于 div 下方。

如果您不明白我的意思,请刷新页面并突出显示所有内容(Cntl A)...您看到描述文字了吗?是啊,我该如何防止这种情况发生?仅在其悬停处于事件状态时显示,而在悬停未处于事件状态时不显示?

这是我的代码,HTML,这只是 div 的第一行(所以是前 2 个框):

        <div id="cube_base">    
            <div id="cube1" onmouseover="portfolio_hover_over(1);">
              <div id="cube_title1">Title
                <div id="cube_logo">
                    <img src="images/icons/photoshop.png" width="20" height="20" border="0" title='Adobe Photoshop'>
                    </div><br/><br/>
                <span class="cube_sub_title">This is a really long description about nothing. Here I begin to talk about nothing, rather interesting isn't it? Text goes here, and is seems like my imagination stops here.</span></div>
            </div>
        </div>

        <div id="cube_div"></div>

        <div id="cube_base">    
            <div id="cube2" onmouseover="portfolio_hover_over(2);">
                <div id="cube_title2">Title
                    <div id="cube_logo">
                        <img src="images/icons/photoshop.png" width="20" height="20" border="0" title='Adobe Photoshop'>
                    </div><br/><br/>
                <span class="cube_sub_title">This is a really long description about nothing. Here I begin to talk about nothing, rather interesting isn't it? Text goes here, and is seems like my imagination stops here.</span></div>
            </div>
        </div>


        <br/>
        <div id="cube_gap"></div>
        <br/>

CSS:

#cube_div{
    float:left;
    width:40px;
    height:100px;
}
#cube_gap{
    width:800px;
    height:40px;
    float:left;
}
.cube_sub_title{
    font-size:12px;
    font-weight: normal;    
}

#cube_title1{
    position:absolute;
    width:335px;
    height:15px;
    background-image: url(images/alpha_black_strong.png);
    background-repeat: repeat;
    bottom:0px;
    padding:10px;
    color:#EEE;
}
#cube_title2{
    position:absolute;
    width:335px;
    height:15px;
    background-image: url(images/alpha_black_strong.png);
    background-repeat: repeat;
    bottom:0px;
    padding:10px;
    color:#EEE;
}
#cube_base{
    width:355px;
    height:200px;
    background-color:#080;
    float:left;
    padding:5px;

    background-color:#f0f0f0;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    webkit-box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    -moz-box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    border-radius:2px 2px 2px 2px;
    border: 1px solid #bbbbbb;
    background-image: url(images/icon_slate.png);
    background-repeat: repeat-x;
    background-position: top;
    cursor:pointer;
}

/* Logo placements */
#cube_logo{
    height:20px;
    float:right;
    left: 50px;
    margin-top:-2px;
}

/* Actual Content for the cube divs */
#cube1{
    position:relative;
    width:355px;
    height:200px;
    background-color: #777;
}
#cube2{
    position:relative;
    width:355px;
    height:200px;
    background-color: #777;
}

还有我的JS:

function portfolio_hover_over(cube){

    // hides the text panel
    for(var i = 1; i < 7; i++){
        if(i != cube){

            //animated panel back to 15px
            $('#cube_title'+i).animate({
                height: '15px'}, 200, function(){
            });
        }
    }


    $('#cube_title'+cube).animate({
        height: '130px'}, 200, function(){
    });


}

我知道这里有很多内容,但我将不胜感激我能在这方面得到的任何帮助,谢谢!

最佳答案

您需要将overflow:hidden 添加到#cube_base css block

关于javascript - jQuery - 文本描述悬停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10450878/

相关文章:

Javascript - 获取任何键盘布局的键描述

javascript - 如何在向下滚动后一一删除具有相同类的元素?

php - 使用PHP中的套接字编程(Erlang)聊天应用程序

javascript - 如何将 URL 从图像的 src 属性复制到 jQuery 中的 href 属性?

javascript - 隐藏元素,但为那个地方显示空白

javascript - JQuery - 使用 'this' 通过一个函数显示和隐藏 DIV

javascript - jQuery.noConflict(); 的作用是什么? jquery-1.4.2.min.js 结尾是什么意思?

javascript - 将两个变量从 onClick 上的另一个 php 返回到两个不同的 div

html - 使用 CSS 更改元素布局而不更改 HTML

javascript - 除了第一行之外,有没有办法用 div 包裹内部文本?