Showing posts with label jQuery Tooltip. Show all posts
Showing posts with label jQuery Tooltip. Show all posts

Custom animation and mouse track with jQuery Tooltip in MVC3 Razor


  1. In this article we will see how to use animation effects with jQuery tooltip and how to achieve mouse track in jQuery tooltip.
  2. Tooltips can be attached to any element. When you hover the element with your mouse, the title attribute is displayed in a little box next to the element, just like a native tooltip.
  3. Tooltips are also useful for form elements, to show some additional information in the context of each field.
  4. The default tooltip shown in different browser limits the number of characters to display, like IE7 shows only 572 characters as default tooltip. Using this jQuery tooltip we can display any number of characters.
  5. We have integrated this tooltip with MVC3 Razor application.

Following are the steps :

We will see how to achieve animation with tooltip first and then will move to mouse track.

Animation :

View :

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>


<p>This is demo for jQuery tooltip. Hover the show link. <a id="show" href="#" title="This is slideDown effect.">show</a></p>
<p>This is demo for jQuery tooltip. Hover the hide link. <a id="hide" href="#" title="On mouse out the tooltip will disappear with explode effect.">hide</a></p>
<p>This is demo for jQuery tooltip. Hover the open link. <a id="open" href="#" title="Tooltip will give effect of opening.">open</a></p>


<script type="text/javascript">
    $(function () {
        $("#show").tooltip({
            show: {
                effect: "slideDown",
                delay: 500
            }
        });
        $("#hide").tooltip({
            hide: {
                effect: "explode",
                delay: 500
            }
        });
        $("#open").tooltip({
            show: null,
            position: {
                my: "left top",
                at: "left bottom"
            },
            open: function (event, ui) {
                ui.tooltip.animate({ top: ui.tooltip.position().top + 20 }, "slow");
            }
        });
    });

</script>

In the above view, we have referred the Layout.cshtml which has references of script files needed for jQuery tooltip and animation effects. We have used slidedown, explode effects.

Layout :



<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-1.8.3.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.core.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.widget.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.position.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.tooltip.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.effect.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.effect-explode.js")" type="text/javascript"></script>
</head>

<body>
    @RenderBody()
</body>
</html>

We have referenced the script filed required for jQuery tooltip and animation. This layout file is reffered in the View.

Demo :





In the above demo, we have set the title attribute of anchor tags. On hovering the links, the tooltip is displayed with animation.

Mouse Track :


View :



@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>

<p title="jQuery Tooltip is amazing !!">This is example for jQuery tooltip. The tooltip will follow the mouse as you move along the paragraph element.</p>


<script type="text/javascript">
    $(function () {
        $("p").tooltip({
            track: true
        })
    });

</script>

In the view we have created one paragraph element. We have set the track attribute to true in order to make the mouse track work for jQuery tooltip.

Layout :


We can use the same layout as above mentioned for animation.


Demo :


Hover the text.


In the above demo, we have created a paragraph element and used the track attribute of jQuery tooltip to achieve mouse track.

Thus by following the above steps we can achieve both animation and mouse track in jQuery tooltip in MVC3 Razor.

Form with jQuery Tooltip in MVC3 Razor


  1. In this article we will create a form and will use jQuery Tooltip for form fields to display additional information.
  2. Tooltips can be attached to any element. When you hover the element with your mouse, the title attribute is displayed in a little box next to the element, just like a native tooltip.
  3. Tooltips are also useful for form elements, to show some additional information in the context of each field.
  4. The default tooltip shown in different browser limits the number of characters to display, like IE7 shows only 572 characters as default tooltip. Using this jQuery tooltip we can display any number of characters.
  5. We have integrated this tooltip with MVC3 Razor application.

Following are the steps :

View :

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>

<fieldset style="width:300px;">
<legend>Employee Information</legend>
<form>
<table>
<tr>
<td>
<label for="FirstName">FirstName</label>
</td>
<td><input type="text" id="FirstName" title="Enter your FirstName Here !! First name should be less than 50 letters." /></td>
</tr>
<tr>
<td>
<label for="LastName">LastName</label>
</td>
<td><input type="text" id="LastName" title="Enter your LastName Here !! Last name should be less than 50 letters." /></td>
</tr>
<tr>
<td>
<label for="Designation">Designation</label>
</td>
<td><input type="text" id="Designation" title="Enter your Designation" /></td>
</tr>
<tr>
<td>
<label for="City">City</label>
</td>
<td><input type="text" id="City" title="Enter your City." /></td>
</tr>
<tr>
<td>
<input type="submit" value="Submit" title="Submits the form" />
</td>
<td><input type="reset" value="Reset" title="Resets the form" /></td>
</tr>
</table>
</form>
</fieldset>


<script type="text/javascript">
    $(function () {
        $(document).tooltip();
    });
</script>

In the above view, we have referenced the layout file. The Layout file has references of all script files needed to render jQuery tooltip. We have created a simple form having some fields. We have rendered the form inside Fieldset element. We have set the title attribute of all the fields. In the script section we have used document selector and applied tooltip to it. When the element having title attribute set to some text is hovered, the text is shown in tooltip window. Thus we can supply additional information about fields and form using jQuery tooltip easily.

Layout :



<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-1.8.3.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.core.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.widget.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.position.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.tooltip.js")" type="text/javascript"></script>
</head>

<body>
    @RenderBody()
</body>
</html>

The above is the layout file. It has references of script files required to use jQuery tooltip. This layout is referenced in View where we want to use jQuery tooltip.

Demo :




In the above demo, on hovering the textboxes tootip is displayed which describes the textbox. We can also use the tab key. In the demo we have used document selector. When any element having title attribute set is hovered, the tooltip is displayed for that element showing text of title attribute.

Thus we can use jQuery tooltip to decorate and to make our form more interactive and interesting.

jQuery Tooltip with custom style and arrow in MVC3 Razor

  1. In this article we will see how to use jQuery Tooltip and customize its style. We will also see how to display arrow with tooltip.
  2. Tooltips can be attached to any element. When you hover the element with your mouse, the title attribute is displayed in a little box next to the element, just like a native tooltip.
  3. Tooltips are also useful for form elements, to show some additional information in the context of each field.
  4. The default tooltip shown in different browser limits the number of characters to display, like IE7 shows only 572 characters as default tooltip. Using this jQuery tooltip we can display any number of characters.
  5. We have integrated this tooltip with MVC3 Razor application.

Following are the steps :

View :

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>

<style>
 .ui-tooltip, .arrow:after {
  background: black;
  border: 2px solid white;
 }
 .ui-tooltip {
  padding: 10px 20px;
  color: white;
  border-radius: 20px;
  font: bold 14px "Helvetica Neue", Sans-Serif;
  text-transform: uppercase;
  box-shadow: 0 0 7px black;
 }
 .arrow {
  width: 70px;
  height: 16px;
  overflow: hidden;
  position: absolute;
  left: 50%;
  margin-left: -35px;
  bottom: -16px;
 }
 .arrow.top {
  top: -16px;
  bottom: auto;
 }
 .arrow.left {
  left: 20%;
 }
 .arrow:after {
  content: "";
  position: absolute;
  left: 20px;
  top: -20px;
  width: 25px;
  height: 25px;
  box-shadow: 6px 5px 9px -9px black;
  -webkit-transform: rotate(45deg);
  -moz-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  -o-transform: rotate(45deg);
  tranform: rotate(45deg);
 }
 .arrow.top:after {
  bottom: -20px;
  top: auto;
 }
 </style>
<a href="#" title="jQuery Tooltip is Amazing !!">jQuery Tooltip</a> provides easy way to implement attractive tooltips.<br /><br  />
<label for="Age">Age :</label>
<input type="text" id="Age" title="Only above 20 are allowed" />


<script type="text/javascript">
    $(function () {
        $(document).tooltip({
            position: {
                my: "center bottom-20",
                at: "center top",
                using: function (position, feedback) {
                    $(this).css(position);
                    $("<div>")
      .addClass("arrow")
      .addClass(feedback.vertical)
      .addClass(feedback.horizontal)
      .appendTo(this);
                }
            }
        });
    });

</script>

In the above view, we have referenced the layout file. The Layout file has references of all script files needed to render jQuery tooltip. We have defined a paragraph element with title attribute. We have defined CSS classes which are applied to tooltip. In the script section we have added the CSS classes to give it unique and good look.

Layout :



<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-1.8.3.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.core.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.widget.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.position.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.tooltip.js")" type="text/javascript"></script>
</head>

<body>
    @RenderBody()
</body>
</html>

The above is the layout file. It has references of script files required to use jQuery tooltip. This layout is referenced in View where we want to use jQuery tooltip.

Demo :


Hover the link and textbox.


In the above demo, we have used document as selector. Using document will apply tooltip to all the elements having title attribute.

Thus by following above steps, we can customize the style and look of jQuery Tooltip. 

jQuery Tooltip in MVC3 Razor


  1. In this article we will see how to use jQuery Tooltip.
  2. Tooltips can be attached to any element. When you hover the element with your mouse, the title attribute is displayed in a little box next to the element, just like a native tooltip.
  3. Tooltips are also useful for form elements, to show some additional information in the context of each field.
  4. The default tooltip shown in different browser limits the number of characters to display, like IE7 shows only 572 characters as default tooltip. Using this jQuery tooltip we can display any number of characters.
  5. We have integrated this tooltip with MVC3 Razor application.

Following are the steps :

View :

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>

<p title="Hello world">This is demo for jQuery Tooltip.</p>


<script type="text/javascript">
    $(function () {
        $("p").tooltip();
    });
</script>


In the above view, we have referenced the layout file. The Layout file has references of all script files needed to render jQuery tooltip. We have defined a paragraph element with title attribute. In the script section we have used tooltip method, when the paragraph element is hovered the jQuery tooltip is displayed. The tooltip function uses the title attribute of element selected to show content in the tooltip window.

Layout :



<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-1.8.3.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.core.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.widget.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.position.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.tooltip.js")" type="text/javascript"></script>
</head>

<body>
    @RenderBody()
</body>
</html>

The above is the layout file. It has references of script files required to use jQuery tooltip. This layout is referenced in View where we want to use jQuery tooltip.

Demo :


Hover the text.


In the above demo, when you hover the paragraph element, its title attribute is used to show the content in the tooltip.

Thus following the above steps we can use jQuery tooltip and can fulfill our requirements.