Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 切换容器 这是集装箱_Javascript_Css_Angularjs_Html - Fatal编程技术网

Javascript 切换容器 这是集装箱

Javascript 切换容器 这是集装箱,javascript,css,angularjs,html,Javascript,Css,Angularjs,Html,问题在于,当您单击按钮时,两个功能都会启动: 指令中的hideContainer 从单击事件(再次显示div)切换容器 解决方案 在计算隐藏回调之前添加 你是怎么做到的 将事件传递给函数data off click=“hideContainer($event)” 在$scope中的hideContainer函数定义中添加$event参数,如下所示:$scope.hideContainer=函数($event) 和完整代码: //角度应用程序代码 var-app=angular.module('

问题在于,当您单击按钮时,两个功能都会启动:

  • 指令中的hideContainer
  • 从单击事件(再次显示
    div
    )切换容器
  • 解决方案

    在计算
    隐藏
    回调之前添加

    你是怎么做到的

  • 将事件传递给函数
    data off click=“hideContainer($event)”
  • $scope
    中的
    hideContainer
    函数定义中添加
    $event
    参数,如下所示:
    $scope.hideContainer=函数($event)
  • 和完整代码:

    //角度应用程序代码
    var-app=angular.module('myApp',['offClick']);
    app.controller('myAppController',['$scope','$timeout',函数($scope,$timeout){
    $scope.showContainer=false;
    $scope.toggleContainer=function(){
    $timeout(函数(){
    $scope.showContainer=!$scope.showContainer;
    }, 300);
    };
    $scope.hideContainer=函数($event){
    $event.stopPropagation();
    $timeout(函数(){
    $scope.showContainer=false;
    });
    };
    }]);
    //Off-Click指令代码
    角度。模块('offClick',[])
    .directive('offClick',['$rootScope','$parse',function($rootScope,$parse){
    var-id=0;
    var侦听器={};
    //添加变量以检测触摸用户的移动。。
    var-touchMove=false;
    //添加事件侦听器以处理各种事件。Destop将忽略触摸事件
    document.addEventListener(“touchmove”,offClickEventHandler,true);
    document.addEventListener(“touchend”,offClickEventHandler,true);
    document.addEventListener('click',offClickEventHandler,true);
    函数targetFilter(目标,elms){
    如果(!target | |!elms)返回false;
    var elmsLen=elms.length;
    对于(变量i=0;i
    
    .container{
    背景:蓝色;
    颜色:#fff;
    高度:300px;
    宽度:300px;
    }
    
    你好,普朗克!
    切换容器
    这是集装箱
    
    请创建一个代码段,这样我们就可以看到问题。我看不到代码段(所以代码段,这样我们就可以看到它在运行)。此外,如果您有问题的更新,请编辑您的问题并添加它(不在评论中)。当你这样做的时候,请告诉我。我在toggleContainer函数中添加了300毫秒的延迟来模拟触摸延迟。我添加了一个明确的问题陈述,请你重新检查。我很困惑。。这个代码有问题吗?因为在我的测试中(在移动设备上),我看不出有问题。谢谢你的回答。然而,这是我尝试的第一个解决方案之一,它将无法工作,因为我需要传播事件。停止传播将停止触发任何后续事件。e、 g.打开另一个下拉菜单OK,我刚刚更新了我的答案。让我知道它是否像你期望的那样对你有效。user5453221这就是你想要的答案吗?