简体   繁体   中英

windows 8 hover to slide effect using css and js

I think css3 alone can make it happen, I'm stuck because I still try to understand things like 'ease' in css3.

my progress so far http://jsfiddle.net/kwgy9/1/

the 'nike' should swipe to left, and 'just do it' appear slowly from right. need help!

$("#box").mouseenter(function(){

}).mouseleave(function(){

});

Try this jsfiddle , I think it's what you want

body {
    font-family:'Fenix', serif;
    text-decoration:none;
    font-size:24px;
    font-weight:bold;
}
#box {
    width: 160px;
    height: 60px;
    background: orange;
    text-align:center;
    border:2px solid orange;
    border-radius:5px;
    cursor:pointer;
    display: inline-block;
    overflow:hidden;
    position:relative;
    transition: all 1s ease;
}

#box:hover {
    color:orange;
    background:#FFF;
}

#box:hover > p {
    left:-160px;
}

#box > p{
    color:white;
    transition: all 1s ease;
    position:absolute;
    top:0px;
    left:0px;
    font-size:24px;
    line-height:60px;
    display:inline-block;
    margin:0px;
    padding:0px;
    width:160px;
}

#box > span{
    white-space:no-wrap;
    position:absolute;
    top:0px;
    left:160px;
    display:inline-block;
    transition: all 1s ease;
    width:160px;
    font-size:24px;
    line-height:60px;
}

#box:hover>span{
    color:orange;
    left:0px;
}

Edit: Sirikon's solution seems to be just fine. The way I did it might still be interesting for you, because of the way the floating elements in the .row are "pushed".

I created a working Fiddle for you:

http://jsfiddle.net/UJsR8/

It still needs some polish, yeah, but I think you'll get the idea playing around with it. It is just one possible solution, mind you.

Hope this helps. Cheers!

The code:

HTML

<div class="slide-box">
    <div class="row">
        <div class="col left">NIKE</div>
        <div class="col right">JUST DO IT</div>
    </div>
</div>

CSS

body {
    font-family:'Fenix', serif;
    text-decoration:none;
    font-size:24px;
    font-weight:bold;
}

.slide-box{
    width:300px;
    height:100px;

    background:orange;

    border:2px solid orange;
    border-radius:5px;

    cursor:pointer;

    overflow:hidden; /* comment this for a visualization of how it works */
}

.slide-box:hover {
    color:orange;
    background:#FFF;
}

.row{
    width:600px;
    height:100px;
}

.col{
    width:200px;
    height:50px;

    padding:25px 50px;

    text-align:center;

    float:left;

    overflow:hidden;
}

JS

$(document).ready(function() {

    var leftWidth,
        leftPaddingX;

    leftWidth = $('.left').width();
    leftWidth = leftWidth + 'px';

    leftPaddingX = $('.left').css('padding-left');

    $('.slide-box').mouseover(function(){
        $('.left').animate({
            width: '0px',
            paddingLeft: '0px',
            paddingRight: '0px'
        }, 300);
    }).mouseleave(function(){
        $('.left').animate({
            width: leftWidth,
            paddingLeft: leftPaddingX,
            paddingRight: leftPaddingX
        }, 300);
    });

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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