I have a small navigation menu with sliding images when the user clicks on the image or an arrow. The images slide by changing their background position over a png image file with a .5s css transition.

当用户点击图像或箭头时,我有一个带滑动图像的小导航菜单。通过使用.5s css转换在png图像文件上更改其背景位置来滑动图像。

When a user clicks on the menu, I grab the x postion of the element & increment it. It takes .5 seconds for this to complete so if the user double clicks while the image is moving it messes up the css position by changing it twice.

当用户点击菜单时,我抓住元素的x位置并递增它。完成此操作需要0.5秒,因此如果用户在图像移动时双击,则会通过将其更改两次来扰乱css位置。

I think the best solution would be to disble the user from double clicking on these buttons within .5s, is there a way to do this?

我认为最好的解决方案是让用户在.5s内双击这些按钮,有没有办法做到这一点?

Below is the relevent excerpt from JS

以下是JS的相关摘录

    function getXAxis (div, val){
        var x_axis = div.css("background-position");
        x_axis = x_axis.split("px");
        x_axis = x_axis[0];
        x_axis = parseInt(x_axis);
        x_axis = x_axis + val;
        return x_axis;
    }

    function rotateControlsRight(){
        x = getXAxis(hpLeftArrow, 9);
        hpLeftArrow.css("background-position", x+"px 0px");
        x = getXAxis(hpPosition1, 57);
        hpPosition1.css("background-position", x+"px -2px");
        x = getXAxis(hpPosition2, 65);
        hpPosition2.css("background-position", x+"px -1px");
        x = getXAxis(hpPosition3, 57);
        hpPosition3.css("background-position", x+"px -2px");
        x = getXAxis(hpRightArrow, 9);
        hpRightArrow.css("background-position", x+"px -15px");
        console.log("moving RIGHT by "+x);

    }

    function rotateControlsLeft(){
        x = getXAxis(hpLeftArrow, -9);
        hpLeftArrow.css("background-position", x+"px 0px");
        x = getXAxis(hpPosition1, -57);
        hpPosition1.css("background-position", x+"px -2px");
        x = getXAxis(hpPosition2, -65);
        hpPosition2.css("background-position", x+"px -1px");
        x = getXAxis(hpPosition3, -57);
        hpPosition3.css("background-position", x+"px -2px");
        x = getXAxis(hpRightArrow, -9);
        hpRightArrow.css("background-position", x+"px -15px");
        console.log("moving Left by "+x);

    }


    hpLeftArrow.click(function(){
        checkForChange = hpSlidePosition;
        hpPrevPosition = hpSlidePosition;
        if (hpSlidePosition > 1 ){
            -- hpSlidePosition;
        } else {
            hpSlidePosition = 1;
        }
        hpMovingRight = false;
        rotateControlsLeft();

        hpInitSlide()

    });

    hpRightArrow.click(function(){
        checkForChange = hpSlidePosition;
        hpPrevPosition = hpSlidePosition;
        if (hpSlidePosition < 3 ){
            ++ hpSlidePosition;
        } else {
            hpSlidePosition = 3;
        }
        hpMovingRight = true;
        rotateControlsRight();

        hpInitSlide()
    });

5 个解决方案

#1


1

May I suggest you to declare some "in progress" flag? For example set some global variable in onclick handler and reset it when animations ends.

我可以建议你宣布一些“进行中”的标志吗?例如,在onclick处理程序中设置一些全局变量,并在动画结束时重置它。

更多相关文章

  1. 使用js / php识别用户,无需登录[重复]
  2. Javascript来自数据库的图像上的图像映射
  3. 用户输入从.csv文件生成新列表?
  4. Cloud Pub / Sub Demo:403未授权用户执行此操作。当试图推送通知
  5. python 简单图像处理(2) 镜像
  6. Django EventLog:传入当前用户
  7. Python基础--图形用户界面GUI
  8. caffe python批量抽取图像特征
  9. 在Python中显示来自控制台的图像

随机推荐

  1. 1563: 高精度加法
  2. 跪求一个java抽奖中奖算法的实现,在线等,急
  3. Cxf 集成spring完整示例
  4. leetcode解题之242# Valid Anagram Java
  5. 自定义视图无法工作,直到我触摸屏幕
  6. RabbitMQ四种Exchange类型之Headers(Java
  7. 将字符串拆分为字符串数组。
  8. Gson将List 反序列化为realmList
  9. 【读书笔记】JavaScript权威指南 第6版 (
  10. java使用compareTo实现一个类的对象之间