繁体   English   中英

检测窗口宽度并更改jQuery UI工具提示位置

[英]Detect window width and change jQuery UI tooltip position

我一直在尝试根据屏幕宽度更改jQuery UI工具提示的位置,但无法正常工作。 [小提琴]有人能告诉我如何检测浏览器的宽度并相应地更改工具提示的位置吗?

$(function () {
    $(document).tooltip({

      var wi = $(window).width();   

        if (wi <= 800){

        position: {
        my: "left+190 top",
        at: "center top"
    },
                        } else {                       
        position: {
        my: "left+20 top",
        at: "center top"  }, }       


        content: function () {
            return $(this).prop('title');
        },
        show: null, 
        close: function (event, ui) {
            ui.tooltip.hover(

            function () {
                $(this).stop(true).fadeTo(400, 1);
            },

            function () {
                $(this).fadeOut("300", function () {
                    $(this).remove();
                })
            });
        }
    });
});

这是无效的代码:

$(document).tooltip({

      var wi = $(window).width();   

        if (wi <= 800){

        position: {
        my: "left+190 top",
        at: "center top"
    },
       }
        else {  

tooltip插件接受一个options object ,它不是在其中编写任意代码的函数体。 将条件窗口大小逻辑移到工具提示之外:

http://jsfiddle.net/XFKN2/3/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM