简体   繁体   English

如何使用jQuery旋转无序列表中的项目符号图像

[英]How to rotate a bullet image in toggled unordered list with jQuery

Ok, I have totally retooled my approach (thank you superUntitled) and am making progress... I have an unordered list that users can toggle and my only remaining issue is that when I expand some items, and then click "Show All Cities" not all of the arrows go in the same direction. 好的,我已经完全改组了我的方法(谢谢superUntitled),并且正在取得进展……我有一个无序的列表,用户可以切换,而我唯一剩下的问题是当我展开某些项目时,然后单击“显示所有城市”并非所有的箭头都朝着相同的方向。 All the arrows change, including the ones on the list items already expanded. 所有箭头都会更改,包括已经展开的列表项上的箭头。 Any suggestions on how to resolve this? 有关如何解决此问题的任何建议?

Here's my new Javascript: 这是我的新Javascript:

   $("#Names .airports").hide();
   $("#Names .close").hide();

   $('#Expand').click(function(){
        $('h2').children(".close").toggle();
        $('h2').children(".arrow-down").toggle();
           if($(this).text() == 'Hide All Cities')
           {
               $(this).text('Show All Cities');
               $('#Names .airports').slideUp('fast');
           }
           else
           {
               $(this).text('Hide All Cities');
               $('#Names .airports').slideDown('fast');
           }
           });

    $("#Names h2").addClass("state").click(function() {  
    $(this).parent().children(".airports").slideToggle('fast')
    $(this).children(".close").toggle();
    $(this).children(".arrow-down").toggle();

Here's the fiddle illustrating the remaining problem: http://jsfiddle.net/d3pxx8ds/127/ 这是说明其余问题的小提琴: http : //jsfiddle.net/d3pxx8ds/127/

Thanks in advance 提前致谢


Here's my old JavaScript (reference only now): 这是我的旧JavaScript(现在仅供参考):

    $(function() {
$('li.state').prepend('<img src="http://png-4.findicons.com/files/icons/2227/picol/32/arrow_sans_up_32.png" class="arrow"/>');});
    $('.stateNames ul').hide();
    $('.stateNames li').click(function(e) {
        e.stopPropagation();
        $(this).find('ul').toggle(); 
        var value = 0
        $(".arrow").rotate({ 
            bind: 
            { 
                click: function(){
                   value +=180;
                $(this).rotate(value)
                }
            } 
        }); 
    });

All i did was replace the order, i moved the .rotate to happen before the .toggle functions this would read the rotate first and subsequently do the toggle function thus setting the variable to 180 instead of waiting for the toggle to start, not allowing the variable to be set 我所做的只是替换订单,我将.rotate移动到.toggle函数之前,这将首先读取旋转,然后执行切换功能,因此将变量设置为180,而不是等待切换开始,不允许要设置的变量

$(function() {
    $('li.state').prepend('<img src="http://png-4.findicons.com/files/icons/2227/picol/32/arrow_sans_up_32.png" class="arrow"/>');
});
$('.stateNames ul').hide();

var value = 0

$(".arrow").rotate({
    bind : {
        click : function() {
            value += 180;
            $(this).rotate(value)
        }
    }
});

$('.stateNames li').click(function(e) {
    e.stopPropagation();
    $(this).find('ul').toggle();

}); 
    $(function() {
    $('li.state').prepend('<img src="http://png-4.findicons.com/files/icons/2227/picol/32/arrow_sans_up_32.png" class="arrow"/>');
});

$('.stateNames ul').hide();

var value = 0
$(".arrow").rotate({ 
    bind: 
     { 
        click: function(){

            value +=180;
        $(this).rotate(value)
        if (value==180){
            value=360;
        }
            else{
              value=180;
            }
        }
     } 
}); 

$('.stateNames li').click(function(e) {
    e.stopPropagation();
    $(this).find('ul').toggle(); 
});

I added the if statement and it works for one full go around but on the next toggle the arrow doesn't rotate hope that helps for now i will keep looking in to it 我添加了if语句,它可以完整播放一次,但是在下一次切换时,箭头不会旋转,希望现在有所帮助,我将继续关注它

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

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