Javascript .children 问题/工具提示

标签 javascript jquery css tooltip children

我正在使用一个简单的 javascript/css 来显示工具提示/放大照片功能。

实际页面可以查here.它是右侧的缩略图。

问题是由于某种原因,mouseenter 函数的工具提示似乎没有拉出正确的图像。它正在工作,但没有拉出正确的图像。它以前工作,但后来我改变了 css。问题是我如何让图像显示在工具提示中,即类工具提示中的图像。谢谢。

<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>';
}
?>

最佳答案

在 listings_layout.css 的第 167 行左右,您有:

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

以 .thumbnail-items 下的所有图像为目标。只需指定您只希望作为 anchor 子项的图像获得宽度和高度。

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

关于Javascript .children 问题/工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21002326/

相关文章:

html - 为什么当我把它们变成链接时我的盒子变平了

javascript - contenteditable - 如何使用 angularjs 仅使标题位于 block 中

javascript - 否定随机正则表达式

javascript - jQuery parents ("tr") 淡出不工作

javascript - MVC 和 javascript 新方法;问 : May I have problems in future with this approach?

jquery - 嵌入在 <object> 或 <embed> 标签中的 PDF 未在 IE 11 中加载

javascript - 如何使用 php 和 mysql 验证单选按钮?

php - 登录信息为纯文本 - 如何使其不可读

HTML 下拉菜单导航不显示

javascript - UWP - Angular 集成