jQuery Mobile: Tooltip

This entry is part 57 of 73 in the series jQuery Mobile

A tooltip can be created by adding a theme swatch to a basic popup and adding padding via the ui-content class.

Here we also show how you can custom style the tooltip button.

<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.css' rel='stylesheet'/>
    <script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
    <script src='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.js'></script>
    <title>Codecrawl</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header' data-theme='b'>
        <h1>A Tooltip App</h1>
    </div>
    <br>
    <br>

    <div data-role='content' style='text-align: center'>
        <p>A paragraph with a tooltip. <a href='#popupInfo' data-rel='popup' data-transition='pop' class='my-tooltip-btn ui-btn ui-alt-icon ui-nodisc-icon ui-btn-inline ui-icon-info ui-btn-icon-notext' title='Learn more'>Learn more</a></p>
        <div data-role='popup' id='popupInfo' class='ui-content' data-theme='a' style='max-width:350px;'>
            <p>Here is a <strong>tiny popup</strong> being used like a tooltip. The text will wrap to multiple lines as needed.</p>
        </div>
    </div>

    <div data-role='footer' data-position='fixed'>
        <h4 style='text-align:center;'>I'm the footer</h4>
    </div>
</div>

</body>
</html>
Try The Code

jQuery Mobile: A basic popup

This entry is part 56 of 73 in the series jQuery Mobile

Popups are useful in many ways.

jQM supports various types of popup.  From a small tooltip to a large photo lightbox.

To create a popup, add the data-role=’popup’ attribute to a <div> with the contents.  Then create a link with the href set to the id of the popup <div>, and add the attribute data-rel=’popup’ to tell the framework to open the popup when the link is tapped.

A popup <div> has to be nested inside the same page as the link.

<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.css' rel='stylesheet'/>
    <script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
    <script src='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.js'></script>
    <title>Upwhere</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header' data-theme='b'>
        <h1>Welcome To My Popup App</h1>
    </div>
    <br>
    <br>

    <div data-role='content' style='text-align: center'>
        <a href='#popupBasic' data-rel='popup' class='ui-btn ui-corner-all ui-shadow ui-btn-inline' data-transition='pop' >Basic Popup</a>
        <div data-role='popup' id='popupBasic'>
            <p>This is a completely basic popup, no options set.</p>
        </div>
    </div>

    <div data-role='footer' data-position='fixed'>
        <h4 style='text-align:center;'>I'm the footer</h4>
    </div>
</div>

</body>
</html>
Try The Code

jQuery Mobile: Dialog box

This entry is part 10 of 73 in the series jQuery Mobile

Instead of going to a page, we can also open pagetwo as a dialog box.

To do that, we add data-dialog=’true’.

<div data-role='page' data-dialog='true' id='pagetwo'>

The only change is in putting data-dialog=’true’ in pagetwo div.

Dialog Box
<!DOCTYPE html>
<html>
<head>
    <link href='http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css' rel='stylesheet'/>
    <script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
    <script src='http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js'></script>
    <title>Upwhere</title>
</head>
<body>
<div data-role='page' id='pageone'>
    <div data-role='header'><h1>My Mobile App</h1></div>
    <div data-role='content'>
        <p>Your page one content here</p>
      <a href='#pagetwo' data-role='button'>Click Me</a>
    </div>
    <div data-role="footer" data-position="fixed">
	<h1>Fixed Footer!</h1>
</div>
</div>
<div data-role='page' data-dialog='true' id='pagetwo'>
    <div data-role='header'><h1>My Mobile App</h1></div>
    <div data-role='content'>
        <p>You are at page two!</p>
        <a href='#pageone' data-role='button'>Go Back</a>
    </div>
</div>

</body>
</html>
Try The Code