首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery的滑入/滑出切换

问jQuery的滑入/滑出切换
EN

Stack Overflow用户
提问于 2012-10-16 05:51:39
回答 1查看 370关注 0票数 0

我正在尝试使用jQuery创建一个幻灯片输出div。当图片悬停在上面时,一个div应该会滑出,部分覆盖照片(其中包含信息)。

我已经把Javascript组装好了,但是我似乎不能让它工作。

信息是display:none的,但当图像悬停在上方时应显示(应从右侧滑出)

http://jsfiddle.net/aHRzv/

EN

回答 1

Stack Overflow用户

发布于 2012-10-16 06:33:26

这里有一种方法:

代码语言:javascript
复制
$("#snoodLink").hover(
    function() {
        $('#snoodInfo').animate({
            left: 0,
            right: 0
        }, 500);
    }, function() {
        $('#snoodInfo').animate({
            left: '-100%',
            right: '100%'
        }, 500);
    });​

它使用以下CSS:

代码语言:javascript
复制
.product {
    /* ensures the positioned text element isn't
       visible before sliding in/after sliding out */
    overflow: hidden;
}
#snoodInfo {
    position: absolute;
    top: 0;
    left: -100%;
    right: 100%;
    width: 100%;
    background-color: rgba(255,255,255, 0.5);
}​

JS Fiddle demo。

顺便说一句,这可以用CSS来完成(对于旧的IE来说,这是一种优雅的降级):

代码语言:javascript
复制
.product {
    position: relative;
    overflow: hidden;
    /* following just center the image/element
       absolutely not necessary */
    width: 50%;
    margin: 1em auto;
}

.product img {
    width: 100%;
}
/* this is the #snoodInfo element, given a class
   insead of id, to make it more generic */
.info {
    position: absolute;
    top: 0;
    left: -100%;
    right: 100%;
    width: 100%;
    /* to enforce the fade-in/fade-out */
    color: transparent;
    background-color: transparent;
    /* trying to cover as many browsers
       as possible, omitting early/old IE
       but filters could (probably) be used */
    -webkit-transition: all 1.5s linear;
    -moz-transition: all 1.5s linear;
    -ms-transition: all 1.5s linear;
    -o-transition: all 1.5s linear;
    transition: all 1.5s linear;
}

.product:hover .info {
    left: 0%;
    right: 0%;
    color: #000;
    background-color: #fff;
    background-color: rgba(215,50,50,0.8);
    -webkit-transition: all 1.5s linear;
    -moz-transition: all 1.5s linear;
    -ms-transition: all 1.5s linear;
    -o-transition: all 1.5s linear;
    transition: all 1.5s linear;
}​

JS Fiddle demo。

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

https://stackoverflow.com/questions/12904590

复制
相关文章

相似问题

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