Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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
Jquery 单击函数和.clone()出现问题_Jquery - Fatal编程技术网

Jquery 单击函数和.clone()出现问题

Jquery 单击函数和.clone()出现问题,jquery,Jquery,我有点奇怪的问题。我正在克隆一个隐藏元素并将其附加到jquery创建的div中。它可以正常工作,但当我单击div的任何子元素(基本上是一个图像和一些文本)时就不行了。如果我单击任何子元素,它就会在克隆发生时动画化,然后停止。在这些元素之外的任何地方,.over div内,都可以正常工作。我的可单击div的html是: <li class="infobox"> <a href="#"><img class="thumb" src="img/10.jpg" alt

我有点奇怪的问题。我正在克隆一个隐藏元素并将其附加到jquery创建的div中。它可以正常工作,但当我单击div的任何子元素(基本上是一个图像和一些文本)时就不行了。如果我单击任何子元素,它就会在克隆发生时动画化,然后停止。在这些元素之外的任何地方,.over div内,都可以正常工作。我的可单击div的html是:

<li class="infobox">
   <a href="#"><img class="thumb" src="img/10.jpg" alt="image10" /></a>
   <div class="over">
   <img src="img/search_icon.png" alt="read more" />
   <h6>New business</h6>
   <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit</p>
   </div>
 </li>
  • 新业务 Lorem ipsum dolor sit amet,奉献精英

  • 我的jquery代码是:

    $('#news_gallery li').click(function(event) {
    
        var index = newsover.index($(this)); //cycle through read more links
        var offset = $(this).offset();  //Get the thumb position to animate from
        var animFinished = false;  //Create boolean to check when ani finishes
    
        $('#news-articles .news-article').hide().eq(index).show(); // show the article for the corresponding link and hide the others
    
        var article = $('#news-articles .news-article').eq(index);
    
    
        // Create the expanded item container
        var expandedItem = $('<div>', {
            id: 'item-expanded',
            css: {
                width: DDBR.constant.ITEM_WIDTH,
                height: DDBR.constant.ITEM_HEIGHT,
                background: '#fff',
                position: 'absolute',
                zIndex: 999
                },  
            });         
    
        // Get the current item offset to animate from
        expandedItem.css({
            top: offset.top,
            left: offset.left,
            overflow: 'hidden',
            opacity: 0
            });
    
        $('body').append(expandedItem);  //Add the shaded overlay and the expanded item to the body
    
        //Animate the size of the expanded item
        expandedItem.animate({
            width: DDBR.constant.ITEM_EXPANDED_WIDTH,
            height: DDBR.constant.ITEM_EXPANDED_HEIGHT,
            left: $(window).scrollLeft() + $(window).width()/2,
            top: $(window).scrollTop() + $(window).height()/2,
            marginTop: -DDBR.constant.ITEM_EXPANDED_HEIGHT/2,
            marginLeft: -DDBR.constant.ITEM_EXPANDED_WIDTH/2,
            opacity: 1
            }, {
                duration: DDBR.constant.ITEM_ANIMATION_SPEED,
                easing: DDBR.constant.ITEM_ANIMATION_EASING,
                queue: false,
                complete: function() {
                    animFinished = true;
                    if (animFinished) {
                        expandFurther();                            
                        }
                    }
                }); 
    
    
        var articleClone = article.clone();  // clone the article for the corresponding link
        var articleHeight = article.actual('outerHeight'); //Get the height of the hidden div
    
        //expand the box further from the center
        expandFurther = function() {
            expandedItem.animate({
                width: 875,
                height: articleHeight,
                marginTop: -articleHeight/2,
                marginLeft: -875/2
                }, {
                    duration: DDBR.constant.ITEM_ANIMATION_SPEED,
                    easing: DDBR.constant.ITEM_ANIMATION_EASING,
                    queue: false,
                    complete: function() {
                        animFinished = true;
                        if (animFinished) {
                        loadContent();
                        }
                    }
                })              
            }; //END expandFurther function
    
        loadContent = function() {
            animFinished = false;       
            expandedItem.append(articleClone);  //Add the cloned image to the expanded item container
            }; //END loadContent function
    
    }); //END click function
    
    $('news#u gallery li')。单击(函数(事件){
    var index=newsover.index($(this));//循环阅读更多链接
    var offset=$(this).offset();//获取要从中设置动画的拇指位置
    var animFinished=false;//创建布尔值以检查ani何时完成
    $('#news articles.news article').hide().eq(index.show();//显示相应链接的文章并隐藏其他链接
    var article=$('#news articles.news article').eq(索引);
    //创建扩展的项目容器
    var expandedItem=$(''{
    id:'项目已展开',
    css:{
    宽度:DDBR.constant.ITEM\u宽度,
    高度:DDBR.constant.ITEM\u高度,
    背景:“#fff”,
    位置:'绝对',
    zIndex:999
    },  
    });         
    //获取要从中设置动画的当前项目偏移量
    expandedItem.css({
    top:offset.top,
    左:offset.left,
    溢出:“隐藏”,
    不透明度:0
    });
    $('body').append(expandedItem);//将着色覆盖和展开项添加到主体中
    //设置展开项目大小的动画
    expandedItem.animate({
    宽度:DDBR.constant.ITEM\u扩展\u宽度,
    高度:DDBR.constant.ITEM\u展开高度,
    左:$(窗口).scrollLeft()+$(窗口).width()/2,
    顶部:$(窗口).scrollTop()+$(窗口).height()/2,
    边距:-DDBR.恒定。项目\扩展\高度/2,
    边缘左侧:-DDBR.constant.ITEM\u EXPANDED\u WIDTH/2,
    不透明度:1
    }, {
    持续时间:DDBR.constant.ITEM\u动画\u速度,
    缓和:DDBR.constant.ITEM\u动画\u缓和,
    队列:false,
    完成:函数(){
    完成=正确;
    如果(完成){
    进一步扩展();
    }
    }
    }); 
    var articleClone=article.clone();//克隆相应链接的文章
    var articlehight=article.actual('outerHeight');//获取隐藏div的高度
    //将长方体从中心进一步展开
    expandFurther=函数(){
    expandedItem.animate({
    宽度:875,
    身高:身高,
    marginTop:-物品高度/2,
    边际收益:-875/2
    }, {
    持续时间:DDBR.constant.ITEM\u动画\u速度,
    缓和:DDBR.constant.ITEM\u动画\u缓和,
    队列:false,
    完成:函数(){
    完成=正确;
    如果(完成){
    loadContent();
    }
    }
    })              
    };//结束函数
    loadContent=函数(){
    完成=错误;
    expandedItem.append(articleClone);//将克隆的图像添加到扩展的项目容器中
    };//结束loadContent函数
    });//结束单击函数
    
    抱歉,代码太多了。正如我所说,只要我在父div中单击任意elese,它就可以正常工作,但在单击div中的子元素时就不行了

    在此方面的任何帮助都将不胜感激。非常感谢。

    代替

    var articleClone = article.clone();  
    
    使用

    这将复制附加到元素的事件,您的问题应该得到解决

    从文件中

    .clone([withDataAndEvents]) withDataAndEvents表示 事件处理程序是否应与元素一起复制。自 jQuery 1.4,元素数据也将被复制


    感谢您的建议,不幸的是,它没有解决问题。当单击“.over”类的子元素时,问题似乎与克隆本身有关。而不是在单击克隆项本身的任何元素时。
     var articleClone = article.clone(true);