单击不在内部div上触发的事件

时间:2012-10-08 20:58:48

标签: jquery html css

如果我在#thumbhider和#thumbcontent div之外使用.thumbnail div,则点击事件可以正常工作并且符合预期。目前他们没有。

网址:http://www.samcoles.co.uk/dustbowl/guitars.php

我猜这与溢出有关:隐藏在包含div上?我该如何解决这个问题?

javascript:

//this is within $(document).ready function
$(".thumbnail").click(function () {

    var IMAGE_DIR = "images/guitars/";
    var img = $(this).find("img").attr("alt");
    $("#mainphoto").attr("src", IMAGE_DIR + img);
    if(captions) {
        $("#imgcaption").text(captions[img]);
    }
}); 

css:

div.thumbnail { background-color: #000000; padding: 1px; float: left; width: 69px; height: 69px; cursor: pointer; }
div#thumbhider { width: 673px; height: 70px; overflow: hidden; margin: 0 auto; margin-top: 19px; position: relative; }
div.thumbcontent { height: 70px; background-color: #00ff00; width: 0 auto; display: inline; position: relative; }

html:

<div id="thumbhider">
        <div class="thumbcontent">
            <div style="margin-right:15px;" class="thumbnail"><img alt="1.png" src="thumber.php?img=images/guitars/1.png&amp;h=69&amp;w=69"></div>
            <div style="margin-right:15px;" class="thumbnail"><img alt="10.png" src="thumber.php?img=images/guitars/10.png&amp;h=69&amp;w=69"></div>

            <!--etc....-->

            <div style="clear:both;"></div>
        </div>
    </div>

1 个答案:

答案 0 :(得分:3)

position:relative

中删除div.thumbcontent
div.thumbcontent {
    height: 70px;
    background-color: lime;
    width: 0 auto;
    display: inline;
    /*position:relative*/
}