Jquery 工具提示插件

发布于 2024-12-19 11:45:06 字数 2115 浏览 0 评论 0原文

我对这个 jquery 插件非常陌生,我开始研究这个工具提示插件:

jQuery(function ($) {
    $.fn.simpleMessageTtip = function (options) {
        var settings = {
            'messageTxt': 'The notification frequency has been updated',
        };

        if (options) {
            $.extend(settings, options);
        }

        var getTooltip = function () {
            var tTip =
                '<div class="simple-message-tooltip">' +
                    '<div class="message clearfix">' +
                        '</div>' +
                            '<div class="bubble-pointer-bottom"></div>' +
                                '</div>';
            return tTip;
        };

        $("body").prepend(getTooltip());

        $(this).each(function () {
            var $this = $(this); //the caller of the ttip
            var tip = $('.simple-message-tooltip');
            var tipInner = $('.simple-message-tooltip .message');

            var setTip = function (top, left) {
                var topOffset = tip.height();
                var xTip = (left - 50) + "px";
                var yTip = (top - topOffset - 40) + "px";
                tip.css({ 'top': yTip, 'left': xTip });
            };

            $this.click(function(){
                var offset = $(this).offset(); //Offset returns an object containing the properties top and left.
                var tLeft = offset.left;
                var tTop = offset.top;

                tipInner.html(messageTxt);
                setTip(tTop, tLeft);
            },
                function () {
                    tip.fadeIn("fast");
                    setTimeout(function(){
                        tip.fadeOut("fast");
                    }, 1000);
                }

            );    
        });

    };
} (jQuery)); 

目前可以工作(你可以说哈哈),但有一些问题。也许你能帮我找出原因?

这是当您单击单选按钮时出现的工具提示。

我的第一个问题是,我希望里面的文本是一个可以稍后更改的设置,以便使插件更具可扩展性...但是目前插件没有给我带来文本=(

另外,它不是 之上,

如果您能帮助我,我将非常优雅!

将工具提示准确地放在用户选择的单选按钮 rel="nofollow">http://jsfiddle.net/Vrfsx/9/

提前感谢大家!! =) 橙汁。-

I am very newby as doing this jquery plugins and I started working on this tooltip plugin:

jQuery(function ($) {
    $.fn.simpleMessageTtip = function (options) {
        var settings = {
            'messageTxt': 'The notification frequency has been updated',
        };

        if (options) {
            $.extend(settings, options);
        }

        var getTooltip = function () {
            var tTip =
                '<div class="simple-message-tooltip">' +
                    '<div class="message clearfix">' +
                        '</div>' +
                            '<div class="bubble-pointer-bottom"></div>' +
                                '</div>';
            return tTip;
        };

        $("body").prepend(getTooltip());

        $(this).each(function () {
            var $this = $(this); //the caller of the ttip
            var tip = $('.simple-message-tooltip');
            var tipInner = $('.simple-message-tooltip .message');

            var setTip = function (top, left) {
                var topOffset = tip.height();
                var xTip = (left - 50) + "px";
                var yTip = (top - topOffset - 40) + "px";
                tip.css({ 'top': yTip, 'left': xTip });
            };

            $this.click(function(){
                var offset = $(this).offset(); //Offset returns an object containing the properties top and left.
                var tLeft = offset.left;
                var tTop = offset.top;

                tipInner.html(messageTxt);
                setTip(tTop, tLeft);
            },
                function () {
                    tip.fadeIn("fast");
                    setTimeout(function(){
                        tip.fadeOut("fast");
                    }, 1000);
                }

            );    
        });

    };
} (jQuery)); 

By the moment is sort of working (you could say lol) but with some problems. Maybe you please help me to find out why?

This is a tooltip that appears when you click on a radiobutton.

My first problem is that I would like the text inside to be a SETTING that can be changed later in order to make the plugin more maleable...But by the moment the plugin is not bringing me the text =(

Also, It is not bringing the tooltip EXACTLY on top of the radiobutton that the user selects.

If you could help me I will be greatly gracefully!!!

This is the fiddle: http://jsfiddle.net/Vrfsx/9/

THANKS IN ADVANCE ALL!! =)
OrangeJuice.-

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞琼窗梦回ˉ 2024-12-26 11:45:07

你已经很接近让它发挥作用了。您唯一需要更改的是您的点击处理程序。以下内容:

$this.click(function(){
    var offset = $(this).offset(); //Offset returns an object containing the properties top and left.
    var tLeft = offset.left;
    var tTop = offset.top;

    tipInner.html(messageTxt);
    setTip(tTop, tLeft);
},
function () {
    tip.fadeIn("fast");
    setTimeout(function(){
    tip.fadeOut("fast");
    }, 1000);
});   

不正确;第一个函数永远不会被执行(由于 click 的重载,有两个参数,最后一个是事件处理程序)现有。要纠正此问题,您所需要做的就是合并两个函数:

$this.click(function() {
    var offset = $(this).offset();
    var tLeft = offset.left;
    var tTop = offset.top;

    tipInner.html(settings.messageTxt);
    setTip(tTop, tLeft);
    tip.fadeIn("fast");
    setTimeout(function() {
        tip.fadeOut("fast");
    }, 1000);
});

更新的代码: http:// /jsfiddle.net/Bky7F/

You're pretty close to having it working. The only thing you need to change is your click handler. The following:

$this.click(function(){
    var offset = $(this).offset(); //Offset returns an object containing the properties top and left.
    var tLeft = offset.left;
    var tTop = offset.top;

    tipInner.html(messageTxt);
    setTip(tTop, tLeft);
},
function () {
    tip.fadeIn("fast");
    setTimeout(function(){
    tip.fadeOut("fast");
    }, 1000);
});   

Is incorrect; the first function will never be executed (due to an overload of click with two arguments, the last being an event handler) existing. All you should have to do to correct this is merge the two functions:

$this.click(function() {
    var offset = $(this).offset();
    var tLeft = offset.left;
    var tTop = offset.top;

    tipInner.html(settings.messageTxt);
    setTip(tTop, tLeft);
    tip.fadeIn("fast");
    setTimeout(function() {
        tip.fadeOut("fast");
    }, 1000);
});

Updated code: http://jsfiddle.net/Bky7F/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文