【问题标题】:How to make rotate occur more than once on click如何在点击时多次发生旋转
【发布时间】:2016-08-05 00:04:12
【问题描述】:

我正在使用以下 JQuery 在单击时将 css 转换插入元素...

$(".menu-item-4828 > a").click(function(){
    $(".sub-menu").css("visibility", "visible");
    $(this).css({
        "-webkit-transform": "rotate(180deg) scale(0)",
        "-moz-transform": "rotate(180deg) scale(0)",
        "transform": "rotate(180deg) scale(0)",
        "-webkit-transition": "-webkit-transform 0.3s ease-in", 
    });

但是,这只会在第一次单击时旋转,之后将不再旋转。我该怎么做才能让它在每次点击元素时旋转?

我尝试添加和删除类,但这不起作用。

【问题讨论】:

标签: javascript jquery css


【解决方案1】:

问题似乎是您将其旋转到 180 度,而不是 180 度。每次单击它时,都会将其设置为旋转 180 度。您需要找出它的当前旋转,添加 180,然后将其设置为该新值。

【讨论】:

    【解决方案2】:

    尝试恢复旋转位置。在您的情况下,这种方式可能没问题(删除样式属性):

        $(".menu-item-4828 > a").click(function(){
           $(".sub-menu").css("visibility", "visible");
           $(this).removeAttr('style').css({
               "-webkit-transform": "rotate(180deg) scale(0)",
               "-moz-transform": "rotate(180deg) scale(0)",
               "transform": "rotate(180deg) scale(0)",
               "-webkit-transition": "-webkit-transform 0.3s ease-in", 
           });
       )};
    

    祝你好运:)

    【讨论】:

      猜你喜欢
      • 2015-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多