简体   繁体   English

jQuery渐变水槽效果按钮

[英]jQuery Gradual Sink Effect Button

There are two ways to do this the way I see it without flash. 有两种方法可以像我没有闪光灯那样看待它。

When you move your mouse over the image; 将鼠标移到图像上时; it gradually changes to the hover class. 它逐渐变为悬停类。 Or when when you hover over the image, the margins change each side going either horizontal either way. 或者,当您将鼠标悬停在图像上时,边距会改变每一侧的水平方向。

The first way would be better but it is CSS at the end of the day. 第一种方式会更好,但它在一天结束时是CSS。 I want this button to gradually sink when you hover over it - and you move your mouse off, it bounces back: 当你将鼠标悬停在它上面时,我希望这个按钮逐渐下沉 - 你将鼠标移开,它会反弹回来:

Html HTML

<center><br /><br />
<a href="#"><img src="//gc-cdn.com/button.png" alt=""></a>
</center>

Css CSS

img{border-right:15px solid #333;border-bottom:15px solid #333}
img:hover{border-right:1px solid #333;border-bottom:1px solid #333}

jsFiddle 的jsfiddle

http://jsfiddle.net/fk6eG/9/ http://jsfiddle.net/fk6eG/9/

You don't need javascript to do this, you can use CSS transitions: 你不需要javascript来做这个,你可以使用CSS转换:

img{
    border-right:15px solid #333;
    border-bottom:15px solid #333;
    -webkit-transition: all 1s ease-in-out;
    -moz-transition: all 1s ease-in-out;
    -o-transition: all 1s ease-in-out;
    -ms-transition: all 1s ease-in-out;
    transition: all 1s ease-in-out;
}
img:hover{border-right:1px solid #333;border-bottom:1px solid #333}​

Updated fiddle: http://jsfiddle.net/fk6eG/15/ 更新小提琴: http//jsfiddle.net/fk6eG/15/

Edit: For a jquery solution, you could use the jquery UI switch class method: 编辑:对于jquery解决方案,您可以使用jquery UI 切换类方法:

CSS: CSS:

 .c1{border-right:15px solid #333;border-bottom:15px solid #333;}
 .c2{border-right:1px solid #333;border-bottom:1px solid #333}​

Javascript: 使用Javascript:

$(".c1").hover(function () {
        $(this).switchClass("c1", "c2", 1000);        
    }, function () {
        $(this).switchClass("c2", "c1", 1000);    
    });​

Sample fiddle: http://jsfiddle.net/fk6eG/23/ 示例小提琴: http//jsfiddle.net/fk6eG/23/

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

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