English 中文(简体)
与单击函数和.clone () 和.clone () 一起的问题
原标题:Issue with click function and .clone()
  • 时间:2012-05-24 16:14:11
  •  标签:
  • jquery

我有一个有点奇怪的问题。 我正在克隆一个隐藏元素, 并把它附在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>

我的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

抱歉的代码范围很广。 正如我所说,只要我点击父子日记里的任何电子字,它就很好,但当我点击公子日记里的儿童元素时则不行。

任何帮助都会十分感激,非常感谢。

问题回答

取代

var articleClone = article.clone();  

使用

 var articleClone = article.clone(true);  

请将附带内容的事件复制至此,您的问题应得到解决。

"http://jsfiddle.net/mprabhat/b6eYg/" rel="nofollow" >Demo

从医生那里

.clone( [与 Data 和 Events 连接] )

与 Data 和 Events 连接

A Boolean indicating whether event handlers should be copied along with the elements. As of jQuery 1.4, element data will be copied as well.





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签