2014-01-08 75 views
0

我正在使用簡單的javascript/css來顯示工具提示/放大照片功能。Javascript .children問題/工具提示

實際頁面可以找到here.這是縮略圖在右側。

問題是,由於某種原因,mouseenter函數,工具提示似乎並沒有拉正確的圖像。它的工作,但不拉正確的形象。它以前工作,但後來我改變了CSS。問題是我如何讓圖像顯示在工具提示中,在類tooltip中顯示圖像。謝謝。

<script type="text/javascript"> 
// Load this script once the document is ready 
$(document).ready(function() { 
    // Get all the thumbnail 
    $('div.thumbnail-item').mouseenter(function(e) { 

     // Calculate the position of the image tooltip 
     x = e.pageX - $(this).offset().left; 
     y = e.pageY - $(this).offset().top; 

     // Set the z-index of the current item, 
     // make sure it's greater than the rest of thumbnail items 
     // Set the position and display the image tooltip 
     $(this).css('z-index','15') 
     .children("div.tooltip") 
     .css({'top': y + 10,'left': x + 20,'display':'block'}); 

    }).mousemove(function(e) { 

     // Calculate the position of the image tooltip   
     x = e.pageX - $(this).offset().left; 
     y = e.pageY - $(this).offset().top; 

     // This line causes the tooltip will follow the mouse pointer 
     $(this).children("div.tooltip").css({'top': y + 10,'left': x + 20}); 

    }).mouseleave(function() { 

     // Reset the z-index and hide the image tooltip 
     $(this).css('z-index','1') 
     .children("div.tooltip") 
     .animate({"opacity": "hide"}, "fast"); 
    }); 
}); 
</script> 
<style> 

.thumbnail-item { 
/* position relative so that we can use position absolute for the tooltip */ 
position: relative; 
float: left; 
margin: 0px 5px; 
} 

.thumbnail-item a { 
display: block; 
} 

.thumbnail-item img.thumbnail { 
border:3px solid #ccc; 
} 

.tooltip { 
/* by default, hide it */ 
display: none; 
/* allow us to move the tooltip */ 
position: absolute; 
/* align the image properly */ 
padding: 8px 0 0 8px; 
} 

.tooltip span.overlay { 
    /* the png image, need ie6 hack though */ 
    background: url(<?php echo base_url(); ?>3_party/imgtooltip/images/overlay.png)  no-repeat; 
    /* put this overlay on the top of the tooltip image */ 
    position: absolute; 
    top: 0px; 
    left: 0px; 
    display: block; 
    width: 350px; 
    height: 200px; 
} 
</style> 
<div class="picture"><?php echo '<img class="main_picture_box" src="' . base_url() .  'uploads/big_' . $main_image->image . '">'; ?></div> 

<div class="thumb-contain"> 
<!--picture loop max 25--> 
<?php 
foreach ($images as $i) { 
    echo '<div class="thumbnail-item">'; 
     echo '<a href="#">'; 
      echo '<img class="test" id="big_pic" onclick="swap()" src="' . base_url() . 'uploads/small_' . $i->image . '" class="thumbnail"/>'; 
     echo '</a>'; 
     echo '<div class="tooltip">'; 
      echo '<img src="' . base_url() . 'uploads/' . $i->image . '" alt="" width="330" height="185" />'; 
      echo '<span class="overlay"></span>'; 
     echo '</div>'; 
    echo '</div>'; 
} 
?> 

回答

1

在listings_layout.css大約線路167你有這樣的:

#tbroker-content .contain .thumb-contain .thumbnail-item img{ 
    width:52px; 
    height:52px; 
    margin:2px; 
} 

靶向所有.thumbnail項下的圖像。只需指定您只需要作爲錨的子項的圖像即可獲取寬度和高度。

#tbroker-content .contain .thumb-contain .thumbnail-item a img{ 
    width:52px; 
    height:52px; 
    margin:2px; 
} 
+0

非常好,這是所有這個字母「a」的問題!快速問題,爲什麼工具提示在右側和底部切斷?再次感謝! – Chad

+0

in listing_layout.css @ line 95'#tbroker-content .contain' set'overflow:initial'或將其刪除。 並在相同的文件@第145行'#tbroker-content .contain .thumb-contain'設置爲'overflow:initial'或將其刪除。 – scottshane