悬停时平滑过渡
Smooth transition on hover
我正在使用jQuery和SVG元素在悬停事件上创建漂亮的动画:
HTML:<div class="chart-picker">
<svg id="user-radio" class="radio" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="25px" height="25px" viewBox="0 0 30 30" enable-background="new 0 0 30 30" xml:space="preserve" onclick="activeUserChart()">
<circle id="center" fill="#F08541" cx="15" cy="15" r="5.733"/>
<circle id="circle" fill="none" stroke="#F08541" stroke-width="4" stroke-miterlimit="10" cx="15" cy="15" r="11.877"/>
</svg>
Active Users
</div>
JS:
$('svg.radio').each(function() {
if (!($(this).attr('class').indexOf('active') > -1))
$(this).find('#center').attr('fill', '#fff');
})
$('.chart-picker').hover(function() {
if (!($(this).find('.radio').attr('class').indexOf('active') > -1))
$(this).find('#center').attr('fill', '#F08641');
}, function() {
if (!($(this).find('.radio').attr('class').indexOf('active') > -1))
$(this).find('#center').attr('fill', '#fff');
})
它工作得很好,但是我想在这里添加一个过渡,让内圆在外圆中褪色。最优雅的方式是什么?我应该坚持使用jQuery还是使用d3.js?
文件如下:
http://jsfiddle.net/2vDue/多谢
这里有一个渐变:http://jsfiddle.net/2vDue/1/
这里是js:
$('svg.radio').each(function() {
if (!($(this).attr('class').indexOf('active') > -1))
$(this).find('#center').hide();
})
$('.chart-picker').hover(function() {
if (!($(this).find('.radio').attr('class').indexOf('active') > -1))
$(this).find('#center').fadeIn();
}, function() {
if (!($(this).find('.radio').attr('class').indexOf('active') > -1))
$(this).find('#center').fadeOut();
})
编辑:忘记那些隐藏的css东西-我本来想隐藏/显示中心元素,直到我想起了fadeIn.
你真的不需要Javascript/jQuery,你可以使用CSS transition
和hover
:
演示:http://jsfiddle.net/abhitalks/2vDue/2/
CSS:
div.chart-picker #center {
opacity: 0;
transition: all 1s;
}
div.chart-picker:hover #center {
opacity: 1;
}
相关文章:
- Html页面上的多个Base64图像和平滑加载
- 当鼠标悬停在文本中的单词上时显示警报
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 手风琴可点击并悬停
- 悬停功能触发器
- Safari(Mac OS)上的jQuery平滑滚动问题
- 如何在鼠标悬停时在另一个图像上滑动图像.
- 鼠标悬停事件影响列表中所有行中的按钮,而不仅仅是特定按钮
- 引导程序:在导航栏中,显示悬停在单个位置的基于Li Link的不同内容
- css(或jQuery)悬停时淡入淡出
- jquery快速悬停问题
- 将鼠标悬停在具有固定高度的无序列表上时平滑滚动
- 如何使悬停背景平滑淡入淡出
- 悬停时使用显示/隐藏 jquery 函数平滑过渡
- jQuery .hover()动画不平滑-悬停效果的小颠簸
- 悬停时平滑过渡
- Jquery不同的图像平滑悬停与背景在所有浏览器上
- 为悬停时显示隐藏跨度的按钮创建平滑过渡
- 悬停时平滑按钮增长和按钮收缩动画
- 如何在鼠标悬停时平滑地插入框阴影效果