Giter Site home page Giter Site logo

jquery.yacsstooltip's Introduction

jquery.YACSSTooltip

Yet Another CSS Tooltip jQuery Plugin - Adds a CSS tooltip for the images in a jQuery selection set.

This small plugin (857 bytes minified and gzipped) adds a visible tooltip to any element with a title or alt attribute:

YACSSTooltip in action

It uses the text in the title attribute first or the text in alt in case the title is not available. To prevent the system's native tooltip to be shown, it disables the title if present, and restores it again after the CSS Tooltip has been hidden.

It takes into account the limits of the viewport so that it doesn't overflow through the right or the bottom. Takes into account long lines and wraps them.

Usage

You can download the minified, ready for production version of the plugin (in the dist folder of this repo) and just reference it from your HTML, after jQuery:

<script src="js/jquery.min.js"></script>
<script src="js/jquery.YACSSTooltip.min.js"></script>

Now, just select the elements you want to add the tooltip to and call the addTooltip method. For example:

$(function() {
    $('.article img').addTooltip();
});

Since its a well behaved jQuery plugin, you can make calls in a fluent way and act over the elements set after adding the tooltip. For example:

$(function() {
    $('.article img').addTooltip().css('border', '5px solid red');
});

in this case we're adding a red solid border to the images after activating the tooltip feature in them.

Check the index.html sample file in the root of this folder to see it in action.

That's it!

Look&Feel

Only one hidden element at the end of the body is used to show as many tooltips as are needed, so it doesn't fill your DOM.

This element has a random id to prevent collisions, and defines the default look&feel as an inline style so that you don't need to add any CSS files to your pages.

However, it has a .YACSSTooltip applied, so you can easily change any default property of the tooltip by adding a CSS selector for that class. You must use the !important modifier to override the inline styles. For example:

.YACSSTooltip {
    border-radius: 0 !important;
}

in order to remove the rounded borders.

Build the production version

In order to build the production version form the source you just need to run the npm build task defined in the package.json file:

npm run build

and it will generate the minified version and the debugging map inside the dist folder. It will automatically add the version in the package to the license comments in the file.

License

This software is released under the permissive MIT license. Check the details here.

jquery.yacsstooltip's People

Contributors

dependabot[bot] avatar jmalarcon avatar

Watchers

 avatar  avatar

Forkers

tecte

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.