我正在尝试确定是否可以在单击功能上切换 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
即使在调用 abort (jQuery) 之后,浏览器也会等待Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在调用 abort (jQuery) 之后,浏览器也会等待 ajax 调用
JavaScript innerHTML 不适用于 IE?JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不适用于 IE?)
XMLHttpRequest 无法加载,请求的资源上不存在“AXMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 无法加载,请求的资
XMLHttpRequest、jQuery.ajax、jQuery.post、jQuery.get 有什么What is the difference between XMLHttpRequest, jQuery.ajax, jQuery.post, jQuery.get(XMLHttpRequest、jQuery.ajax、jQuery.post、jQuery.get 有什么区别
可以使用 xhrFields 将 onprogress 功能添加到 jQuery.Can onprogress functionality be added to jQuery.ajax() by using xhrFields?(可以使用 xhrFields 将 onprogress 功能添加到 jQuery.ajax() 吗?)
显示使用 XHR2/AJAX 下载文件的进度条Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)