powertip是一个基于jQuery的灵活美观的工具提示插件,支持复杂的数据。它是高度可定制的,并提供了许多不同的方法来使用工具提示。
1.在页面的头部包含必要的javascript文件
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script> <script type="text/javascript" src="../src/core.js"></script> <script type="text/javascript" src="../src/csscoordinates.js"></script> <script type="text/javascript" src="../src/displaycontroller.js"></script> <script type="text/javascript" src="../src/placementcalculator.js"></script> <script type="text/javascript" src="../src/tooltipcontroller.js"></script> <script type="text/javascript" src="../src/utility.js"></script>
2.包含jQuery powertip CSS以设置工具提示样式
<link rel="stylesheet" type="text/css" href="../css/jquery.powertip.css" />
3.标记
<input type="button" class="north-west-alt" value="North West Alt" title="North west alt placement" />
4.调用插件并设置工具提示的位置。
<script type="text/javascript"> $(function() { $('.north-west').powerTip({ placement: 'nw' }); }); </script>
5.所有可用选项。
$('.element').powerTip({ // Boolean If set to true the tooltip will follow the users mouse cursor. followMouse: false, // Boolean Allow the mouse to hover on the tooltip. This lets users interact with the content in the tooltip. Only works if followMouse is set to false. mouseOnToPopup: false, // When enabled the plugin will try to keep tips inside the browser view port. // If a tooltip would extend outside of the view port then its placement will be changed to an orientation that would be entirely within the current view port. // Only applies if followMouse is set to false. smartPlacement: false, // Placement location of the tooltip relative to the element it is open for. // Values can be n, e, s, w, nw, ne, sw, se, nw-alt, ne-alt, sw-alt, or se-alt (as in north, east, south, and west). // This only matters if followMouse is set to false. placement: 'n', // String HTML id attribute for the tooltip div. popupId: 'powerTip', // Number Pixel offset of the tooltip. This will be the offset from the element the tooltip is open for, or from from mouse cursor if followMouse is true. offset: 10, // Number Tooltip fade-in time in milliseconds. fadeInTime: 200, // Tooltip fade-out time in milliseconds. fadeOutTime: 100, // Time in milliseconds to wait after mouse cursor leaves the element before closing the tooltip. // This serves two purposes: first, it is the mechanism that lets the mouse cursor reach the tooltip (cross the gap between the element and the tooltip div) for mouseOnToPopup tooltips. // And, second, it lets the cursor briefly leave the element and return without causing the whole fade-out, intent test, and fade-in cycle to happen. closeDelay: 100, // Hover intent polling interval in milliseconds. intentPollInterval: 100, // Hover intent sensitivity. // The tooltip will not open unless the number of pixels the mouse has moved within the intentPollInterval is less than this value. // These default values mean that if the mouse cursor has moved 7 or more pixels in 100 milliseconds the tooltip will not open. intentSensitivity: 7, // If set to true then PowerTip will not hook up its event handlers, letting you create your own event handlers to control when tooltips are shown (using the API to open and close tooltips). manual: false, openEvents: [ 'mouseenter', 'focus' ], closeEvents: [ 'mouseleave', 'blur' ] });
v1.3.2 (2022-03-07)
v1.3.1 (2018-10-15)
v1.3.0 (2017-01-16)