我有一个有点奇怪的问题。 我正在克隆一个隐藏元素, 并把它附在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
抱歉的代码范围很广。 正如我所说,只要我点击父子日记里的任何电子字,它就很好,但当我点击公子日记里的儿童元素时则不行。
任何帮助都会十分感激,非常感谢。