jQuery: Toggle rotate div on click function(jQuery:在点击功能上切换旋转 div)
问题描述
我正在尝试确定是否可以在单击功能上切换 div 的旋转,例如单击菜单按钮可将箭头从向下旋转到向上,再次单击将反转(从上到下).
我有一个 jsfiddle 演示设置,它会更有意义:http://jsfiddle.net/bf7Ke/1/
jQuery —
I'm trying to work out if it's possible to toggle the rotation of a div on a click function, e.g. Clicking on a menu button rotates the arrow from pointing downwards to upwards and clicking again will reverse this (upwards to downwards).
I have a jsfiddle demo setup which will make more sense of it: http://jsfiddle.net/bf7Ke/1/
jQuery —
$(document).ready(function(){
$('.menu-category-title').click(function(){
$('#menu-'+$(this).attr('hook')).fadeToggle('slow');
$(this).children('.menu-title-arrow').rotate({animateTo:180});
return false;
});
});
到目前为止,单击 .menu-category-title
会淡入下面的相关内容并将相应的箭头旋转 180 度.再次单击 .menu-category-title
会淡出相关内容,但箭头保持在 180 度.无论如何也可以切换此功能?
我无法弄清楚,任何建议将不胜感激!
Thus far clicking on .menu-category-title
fades in the relevant content below and rotates the corresponding arrow by 180 degrees. Clicking .menu-category-title
again fades out the relevant content but the arrow stays at 180 degrees. Is there anyway to toggle this function also?
I can't figure it out, any suggestions would be greatly appreciated!
推荐答案
认为你应该在箭头旋转之前检查元素是否可见
Think you should check if element is visible or not before arrow rotation
$(document).ready(function(){
$('.menu-category-title').click(function(){
var elem = $('#menu-'+$(this).attr('hook')),
arrow = $(this).children('.menu-title-arrow')
if (!elem.is(':visible')) {
arrow.rotate({animateTo:180});
} else {
arrow.rotate({animateTo:360});
}
elem.fadeToggle('slow', function() {
});
return false;
});
});
http://jsfiddle.net/bf7Ke/2/
这篇关于jQuery:在点击功能上切换旋转 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:jQuery:在点击功能上切换旋转 div


- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Flexslider 箭头未正确显示 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01