简体   繁体   English

滑动背景图片效果

[英]Swiping effect on background Images

Hi I would like to reproduce a sort a slider effect between background images like the website http://www.moveline.com/ does on the home page. 嗨,我想在背景图片之间重现某种滑块效果,就像网站http://www.moveline.com/在首页上所做的那样。

Example section bellow the title: "Mapping out the details for your next move". 示例部分的标题为:“为您的下一步提供详细信息”。

I look at the code they use jQuery, RequireJS (2.1.4) 我看看他们使用jQuery,RequireJS(2.1.4)的代码

I try to isolate the code that is producing that effect but the JavaScript code has been compressed which make it really hard to understand (plus they use backbone). 我试图隔离产生这种效果的代码,但是JavaScript代码已经压缩,这使得它真的很难理解(加上他们使用主干)。

Any idea how i could reproduce this nicely probably in jQuery with the help of some plugin? 知道我如何借助一些插件在jQuery中很好地重现这一点吗?

Thank you 谢谢

Here's a working fiddle for almost what they're doing on their site http://jsfiddle.net/y29kR/2/ 这是他们在网站http://jsfiddle.net/y29kR/2/上所做的几乎所有工作的提琴

Html: HTML:

<div class="items">
    <div class="menu-item" data-look-at="0 0">item1</div>
    <div class="menu-item" data-look-at="-40px -70px">item2</div>
    <div class="menu-item" data-look-at="-120px -30px">item3</div>
</div>
<div class="menu-content"></div>

CSS with css transitions on background-position CSS在背景位置上具有CSS过渡

.items {
    float:left;
}
.menu-item {
    padding: 15px;
    color: #333;
    border-bottom: 1px solid #ccc;
    width: 70px;
}

.menu-content {
    height: 150px;
    width: 150px;
    background-repeat: no-repeat;
    background-image: url("http://placehold.it/350x350");
    background-position: center center;
    float:left;
    -webkit-transition: background-position 600ms ease;
    -moz-transition: background-position 600ms ease;
    -o-transition: background-position 600ms ease;
}

I'm using jQuery's .css method to detect hover event to produce the (almost) desired effect: 我正在使用jQuery的.css方法来检测悬停事件以产生(几乎)所需的效果:

jQuery(document).ready(function() {
    $('.menu-item').hover(function(e) {
        var target = $(e.target),
            newPos = target.data("look-at");
        $('.menu-content').css({'background-position': newPos}); 
    });
    $('.items').mouseleave(function(e) {  
        $('.menu-content').css({'background-position': 'center center'}); 
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM