Центр всплывающей подсказки и удерживать на месте при наведении курсора? - PullRequest
0 голосов
/ 28 февраля 2012

На этом сайте videon

Я реализовал скрипт всплывающей подсказки, который показывает разные изображения, когда родительское изображение находится над ним.Хотя изображения всплывающей подсказки не центрированы непосредственно над родительскими изображениями.

Может ли кто-нибудь дать представление о том, что мне нужно изменить, чтобы изображение всплывающей подсказки отображалось по центру родительского изображения?

Вот 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','101')
            .children("div.tooltip")
            .css({'top': y + -400,'left': x + -115,'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 + -400,'left': x + -105});

        }).mouseleave(function() {

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

    });

1 Ответ

0 голосов
/ 28 февраля 2012

Не используйте положение события мыши в расчетах.Смещение большого пальца (). Влево плюс 1/2 его ширина будет в центре

...