响应图像悬停 - CSS / JQuery [英] Responsive Image Hover - CSS/JQuery

查看:137
本文介绍了响应图像悬停 - CSS / JQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照本教程( http:// mattbango.com/notebook/code/hover-zoom-effect-with-jquery-and-css/ ),并建立了一个我想在我的网站上使用的图像悬停插件。

I followed this tutorial (http://mattbango.com/notebook/code/hover-zoom-effect-with-jquery-and-css/) and built out a image-hover plugin that I'd like to use on my site.

我唯一的问题是,我想让它工作响应,缩放图像根据我的960gs。

The only problem I have is that I want it to work responsively, scaling the images according to my 960gs.

这里是fiddle我到目前为止: http://jsfiddle.net/Ak94R/6/

Here's the fiddle I have so far: http://jsfiddle.net/Ak94R/6/

.viewport {
    float: left;
    height: 360px;
    margin: 0 9px 9px 0;
    overflow: hidden;
    position: relative;
    width: 360px;

}

从730px / 730px到360px / 360px,我想把它从200%收缩到100%。我还需要主剪辑div(.viewport)的大小为100%。

Instead of shrinking that image from 730px/730px to 360px/360px, I want to shrink it from 200% to 100%. I also need the main clipping div (.viewport) to be sized at 100%. Any help would be greatly appreciated!

推荐答案

好,我只花了几分钟时间来获得 CSS only solution 。做同样的事情,没有JS需要。充分响应,因为它与百分比。 HTML如下所示:

Ok, I've just spend a few minutes for a CSS only solution. Does the same thing and no JS required. Fully responsive since it works with percentages. The HTML looks like this:

<div class="viewport_css">
    // I have to use a dummy image to force dimensions
    <img class="dummy" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" />
    <a class="imgwrapper" href="#">
        <img src="http://www.lorempixel.com/730/730/" alt="More Info" />
    </a>
</div>

CSS部分:

.viewport_css {
    position: relative;
    max-width: 360px;
    height: auto;
    overflow: hidden;
}

// make sure viewport_css always is square shaped
.viewport_css .dummy {
    width: 100%;
    height: auto;
    display: block;
}

.viewport_css a,
.viewport_css a:hover:before,
.viewport_css a:hover:after {
    position: absolute;
    left: 0;
    right: 0;
}
.viewport_css a,
.viewport_css a:hover:after {
    top: 0;
    bottom: 0;
}

.viewport_css a:hover:after {
    content: '';
    display: block;
    z-index: 100;
    background-color: rgba(255, 0, 0, .5);    
}

.viewport_css a:hover:before {
    content: 'View';
    color: #fff;
    top: 50%;
    text-align: center;
    z-index: 200;
    margin-top: -0.5em;
}

.viewport_css .imgwrapper {
    width: 200%;
    height: 200%;
    margin-left: -50%;
    margin-top: -50%;
    transition: all 1s ease-in;  
}

.viewport_css .imgwrapper img {
    width: 100%;
    height: auto;
    display: block;
}

.viewport_css .imgwrapper:hover {
    width: 100%;
    height: 100%;
    margin-left: 0;
    margin-top: 0;
}

这篇关于响应图像悬停 - CSS / JQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆