简体   繁体   中英

jQuery UI Bounce Effect with CSS Sprite Image

Im trying to make my social icons bounce using the jQuery UI Bounce Effect. Im working off a template & some docs from jQuery. The rest im just trying to write the HTML,CSS & JS myself so i probably have some errors in there. Im having a problem getting the icons to bounce. I think it could be because im using a sprite image for the social icons.

Can someone take a look at it and help me out?

The jQuery & jQuery UI in the header

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"</script>

The CSS being used:

#footer {background:#1c1c1c; padding:40px 0 20px;  border-top:4px solid #fff;}
#footer a {color:#fff;}
#footer a:hover {color:#d5d5d5;}

#footer .social-icons {float:right;}
#footer .copyright img {float:left; margin-right:20px;}

#footer .copyright p {
font-size:80%;
line-height:140%;
}

#footer .social-icons { }
#footer .social-icons li.title {line-height:30px;}
#footer .social-icons li {margin:0 0 0 10px; }
#footer .social-icons li:first-child {margin-left:0;}

/* social icons */
.social-icons {margin:0 0 20px;}
.social-icons li {display:inline-block; margin:5px;vertical-align: middle;}
.social-icons li a {display:inline-block; width:30px; height:30px; text-indent:-9999px;     background-image:url(../images/social-icons-sprite.png); background-repeat: no-repeat;     position:relative; background-color: #111; -webkit-border-radius:3px; -moz-border-    radius:3px; border-radius:3px;
-webkit-transition: all 0.2s ease-out; -moz-transition: all 0.2s ease-out; -o-    transition: all 0.2s ease-out; transition: all 0.2s ease-out; }
.social-icons li a:hover {background-color:#cd2122; box-shadow:0 0 6px rgba(0,0,0,0.4)}

.social-icons li.social-twitter a {background-position:0 0;}
.social-icons li.social-dribbble a {background-position:-30px 0;}
.social-icons li.social-facebook a {background-position:-60px 0;}
.social-icons li.social-envato a {background-position:-90px 0;}

The HTML of where the icons are positioned.

<div id="footer">
        <div class="row">
            <div class="span12">
                <div class="bottom fixclear">
                    <ul class="social-icons fixclear">
                        <li class="title">SOCIAL LOVE</li>
                        <li class="social-twitter">
                            <a href="#">Twitter</a>
                        </li>
                    </ul>

Finally, the JS i think need to insert and run correctly.

<style type="text/css">
footer li.social-twitter {
width: 32px;
height: 32px;
}
</style>
<script>
$(document).ready(function() {

$("div").mouseenter(function () {
$(this).effect("bounce", { times:3 }, 270);
});

});
</script>

You could use @keyframes animation for this effect.

@keyframes bounce {
0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
}
40% {
    transform: translateY(-30px);
}
60% {
    transform: translateY(-15px);
}
}

Check out Animate.css Dan Eden has created a plug and play animation library that is very cool for things like this.

You can achieve the same bouncing effect using only CSS3. The @keyframes and animation properties will do the job. Here is the working example in JSFiddle . Each image bounces on hover .

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