简体   繁体   English

使用Prototype.js的工具提示

[英]Tooltip using Prototype.js

It seems so hard to find a easy to use tooltip for Prototype library. 为Prototype库找到一个易于使用的工具提示似乎很难。 The ones that are out there are so bloated. 那些在那里的人是如此臃肿。

What I am looking for is something as simple as this. 我正在寻找的东西就像这样简单。

<a class="tooltip">This is my sentence<span>Tooltip is here</span> that ends in sorrow.</a> <a class="tooltip">How can I make this happen <span>like how?</span> without killing people.</a>

I have a CSS solution but the problem is once the tooltip is near edge of browser, it goes off the edge. 我有一个CSS解决方案,但问题是一旦工具提示靠近浏览器的边缘,它就会脱离边缘。 I like it to be smart and not go off the edge of browser window. 我喜欢它是聪明的,而不是走出浏览器窗口的边缘。

Anyways? 无论如何? I was thinking of using Prototype to find the xy coordinates of pop-up and move it. 我正在考虑使用Prototype来找到弹出窗口的xy坐标并移动它。 but how to do it? 但怎么办呢?

This is what I am using for CSS 这就是我用于CSS的内容

.date_info a:hover {background:#ffffff; text-decoration:none;} /*BG color is a must for IE6*/
.date_info a.tooltip span {display:none; padding:2px 3px; margin-left:8px; width:200px;}
.date_info a.tooltip:hover span{display:inline; position:absolute; background:#ffffff; border:1px solid #555; color:#6c6c6c;}

There's a good tooltip project for prototype called prototip2 , have you checked this out? 有一个很好的工具提示项目原型名为prototip2 ,你有没有检查过这个? even if you dont end up using it it might be helpful to have a dig around in the code to get some ideas, or is this one of the bloated ones you referred to? 即使你最终没有使用它,在代码中挖掘一些想法可能会有所帮助,或者这是你提到的臃肿的一个?

If it helps, this is a snippet of prototype js i put together that detects if an element is within the viewport or not which might get you started if you're not happy with the other solution. 如果有帮助的话,这是我放在一起的原型js的片段,它检测一个元素是否在视口内,如果你对另一个解决方案不满意,可能会让你开始。

function withinViewport(el) {
    var elOffset = $(el).cumulativeOffset(el);
    vpOffset = document.viewport.getScrollOffsets();
    elDim = $(el).getDimensions();
    vpDim = document.viewport.getDimensions();
    if (elOffset[1] + elDim.height < vpOffset[1] || elOffset[1] > vpOffset[1] + vpDim.height ||
        elOffset[0] + elDim.width < vpOffset[0]  || elOffset[0] > vpOffset[0] + vpDim.width) {
        return false;
    }
    return true;
}

you could use this something like: 你可以使用这样的东西:

if(!withinViewport($(el)){
  // move me - add padding / margin or something like that
}

You can fine below links as a good resources for Prototype tooltips: 你可以在链接下面作为Prototype工具提示的一个很好的资源:

1] Prototip 1] Prototip

2] Prototip2 2] Prototip2

3] Cooltips 3] Cooltips

Those are three resource i found very interesting and helpful. 这三个资源我发现非常有趣和有帮助。

CoolTips seems right up your alley. CoolTips似乎正好在你的小巷里。

I have not checked it yet. 我还没检查过。 I think you can use Opentip which is a tool tip framework. 我认为你可以使用Opentip这是一个工具提示框架。 You can choose one for your framework. 您可以为您的框架选择一个。 It is there for prototype also. 它也适用于原型。 If you are not intended to support IE8, you don't have to use -excanvas file. 如果您不打算支持IE8,则不必使用-excanvas文件。 If you are not intended to debug, you will be a happy user with 'min.js' 如果您不打算进行调试,那么'min.js'将是一个快乐的用户

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

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