0

Saw this slide down reveal effect on CodePen, I was wondering if anyone could help me recreate it using jQuery? The effect can be found here. While I understand what's going on with CSS, I would like to create this effect using jQuery/JavaScript.

HTML:

    <section>
    <div id="icon-wrapper">
        <a href="map.html">
            <div class="icons">
                <div class="icon-slide-container">
                    <img class="slide-icon"  alt="The Kite Map Logo" height="100" src="http://thekitemap.com/images/slide/view-map.jpg">
                </div>
            </div>
        </a>
    </div>
</section>

CSS:

    body{
  background:#eeeeee;
}

section{
    float: left;
    padding-top: 50px;
    padding-bottom: 100px;
    width: 100%;
    padding-left:0;
    padding-right:0;
}

#icon-wrapper{
    width:100%;
    float:left;
    height:300px;
}

.icons {
    width:25%;
    float:left;
    position:relative;
}

.icon-slide-container{
    height:300px;
    overflow:hidden;
    text-align: left;
    position: absolute;
    float: left;
    width: 300px;
    left: 50%;
    margin-left: -150px;
}

.slide-icon{
    width:300px;
    height:auto;
    position:absolute;
    margin-top:-300px;
    -webkit-transition:.4s ease;
    -moz-transition:.4s ease;
    -ms-transition:.4s ease;
    -o-transition:.4s ease;
    transition:.4 ease;
}

.slide-icon:hover{
    position:absolute;
    margin-top:0;
}
5
  • 2
    Out of curiosity, if you understand how it works in CSS and it does indeed work as you want it to, why do you want to implement it in jQuery? Commented Jul 15, 2014 at 17:20
  • I guess, 1) I want become better at JS 2) I need to work the same on older browsers. But really, I want to get better writing JS. Commented Jul 15, 2014 at 17:26
  • since you haven't provided any code attempts... would appear you want somone to create it for you. Where's the learning in that? Commented Jul 15, 2014 at 17:28
  • 1
    The slide methods in jQuery are where you should start, but CSS is a far simpler solution. And if you want to get better at JS, asking folks to "help me recreate it using jQuery" won't help you get better. Give it a shot yourself first and then come here with specific questions. Commented Jul 15, 2014 at 17:28
  • No, I tried... I may not copied any of the code I did, but then again... a lot of the code I wrote... Hell, just looked like chicken scratch. Won't learn copying other code, but when you don't know where to start or have any clue... makes it more difficult. Thanks @ChrisWillard pointing in me in a direction. Commented Jul 15, 2014 at 18:09

1 Answer 1

1

I agree that you should've posted your attempt. Here's a simple start:

http://jsfiddle.net/isherwood/9Lwk8/

.wrapper {
    width: 200px;
}
.wrapper > div {
    height: 200px;
}
.text {
    display: none;
    background-color: #eee;
    overflow: hidden;
}

<div class="wrapper">
    <div class="text">
         <h1>Some text</h1>
    </div>

    <div class="image">
        <img src="http://placekitten.com/200/200" />
    </div>
</div>

$('.wrapper').hover(function () {
    $('.image').slideUp();
    $('.text').slideDown();
}, function () {
    $('.image').slideDown();
    $('.text').slideUp();
});

To get the text div to slide in from above you'd need to animate margin-top or somesuch. jQuery has excellent documentation, so give it a look.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you @isherwood. One last thing, would using mouseenter and mouseleave be correct when starting and resetting the animation margin-top?
"The .hover() method binds handlers for both mouseenter and mouseleave events. You can use it to simply apply behavior to an element during the time the mouse is within the element." api.jquery.com/hover

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.