基于jQuery实现Taggd图像标签提示特效



85 339 114



特效描述:基于jQuery实现 Taggd 图像标签提示,基于jQuery实现Taggd图像标签提示特效

代码结构

1. 引入CSS

<link rel="stylesheet" type="text/css" href="css/normalize.css" />
<link rel="stylesheet" type="text/css" href="css/taggd.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />

2. 引入JS

<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/jquery.taggd.js"></script>

3. HTML代码

<div id="container">
    <div id="example">
        <img class="taggd" src="img/example.jpg" alt="photo" />
        <script type="text/javascript">
            data.push([
                { x: 0.512, y: 0.33, text: 'Huey' },
                { x: 0.548, y: 0.33, text: 'Dewey' },
                { x: 0.567, y: 0.36, text: 'Louie' }
            ]);
            settings.push({
                align: { 'y': 'bottom' },
                offset: { 'top': -15 },
                'handlers': {
                    'mouseenter': 'show',
                    'mouseleave': 'hide'
                }
            });
        </script>
    </div>
    <div class="content-wrapper">
	<img src="img/taggd.png" class="logo" alt="taggd" />
    <p>
        <strong>“A picture is worth a thousand words”</strong>, but sometimes 
		even a thousand words are just not enough.<br />
        <strong>Taggd</strong> is a jQuery plugin that help you create tags on images with, or without a 
		popup!
    </p>
    <ol>
        <li>
            <a href="#begin">Getting started</a>
            <ol>
                <li><a href="#download">Download</a></li>
                <li><a href="#basic-usage">Basic usage</a></li>
                <li><a href="#custom">Customization</a></li>
            </ol>
        </li>
        <li>
            Documentation
            <ol>
                <li>
                    <a href="#configuration">Configuration</a>
                    <ol>
                        <li><a href="#align">Align Object</a></li>
                        <li><a href="#handler">Handler Object</a></li>
                        <li><a href="#offset">Offset Object</a></li>
                    </ol>
                </li>
                <li>
                    <a href="#items">Items</a>
                    <ol>
                        <li><a href="#item">Item Object</a></li>
                    </ol>
                </li>
            </ol>
        </li>
        <li>
            Demo&#39;s
            <ol>
                <li><a href="#demo-0">Hover top popup</a></li>
                <li><a href="#demo-1">Click bottom popup</a></li>
                <li><a href="#demo-2">Click-mouseout left popup</a></li>
                <li><a href="#demo-3">Click custom</a></li>
            </ol>
        </li>
    </ol>
</div>
    <div id="begin">
        <div class="content-wrapper">
    <h2>Getting started</h2>
    <p>But, without data, there are no tags! We have to write just one more 
	line:</p>
    <pre>$( image ).taggd( &#39;items&#39;, data );</pre>
    <p>Read <a href="#items">Items</a> to learn how to set up the data.</p>
    <h3 id="custom">Customization</h3>
    <p>Of course, sometimes you want to do more than just a popup. By discarding 
	the <code>text</code> property of the <a href="#items">items</a>, and using 
	a function as <a href="#handler">Handler</a>, you can do whatever you want, 
	just like <a href="#demo-3">this demo</a>. If you need item-specific data in 
	the Handler, you can just add more properties to the <a href="#item">Item 
	Object</a>.</p>
    <p>CSS styles are easily customizable. Just edit or replace the CSS rules in 
	the file <code>css/taggd.css</code>.</p>
</div>
    </div>
    <div class="content-wrapper">
    <h2 id="configuration">Configuration</h2>
    <table>
        <thead>
        <tr>
            <td>Property</td>
            <td>Value</td>
            <td>Description</td>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>align</td>
            <td><a href="#align">Align Object</a></td>
            <td>Popup aligning settings</td>
        </tr>
        <tr>
            <td>handlers</td>
            <td><a href="#handler">Handler Object</a></td>
            <td>Event handlers</td>
        </tr>
        <tr>
            <td>offset</td>
            <td><a href="#offset">Offset Object</a></td>
            <td>Offset of the hover element in pixels</td>
        </tr>
        </tbody>
    </table>
</div>
<div class="content-wrapper">
    <h3 id="align">Align Object</h3>
    <p>Aligning is two-dimensional; the X-axis and the Y-axis. When you align an 
	object <strong>left</strong>, the <strong>left side</strong> is snapped 
	against the button.</p>
    <table>
        <thead>
        <tr>
            <td>Property</td>
            <td>Value</td>
            <td>Default</td>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>x</td>
            <td><code>String</code> left, right or center</td>
            <td>center</td>
        </tr>
        <tr>
            <td>y</td>
            <td><code>String</code> top, bottom or center</td>
            <td>center</td>
        </tr>
        </tbody>
    </table>
    <h4>Example</h4>
    <pre>{
    x: 13,
    y: 37
}</pre>
</div>
<div class="content-wrapper">
    <h3 id="handler">Handler Object</h3>
    <p>Handlers are used to add actions to the buttons. These are JavaScript 
	events like <code>click</code>, <code>mouseenter</code>, etc.<br />The 
	handler can be a function, or a string for popup interaction.</p>
    <table>
        <thead>
        <tr>
            <td>String</td>
            <td>Description</td>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>show</td>
            <td>Shows the popup</td>
        </tr>
        <tr>
            <td>hide</td>
            <td>Hides the popup</td>
        </tr>
        <tr>
            <td>toggle</td>
            <td>Toggles the popup visability</td>
        </tr>
        </tbody>
    </table>
    <h4>Example</h4>
    <pre>{
    click: function() {
        alert(&#39;You clicked the tag!&#39;);
    },
    mouseenter: &#39;show&#39;,
    mouseleave: &#39;hide&#39;
}</pre>
</div>
<div class="content-wrapper">
    <h3 id="offset">Offset Object</h3>
    <p>The offset is the offset of the popup in pixels.</p>
    <table>
        <thead>
        <tr>
            <td>Property</td>
            <td>Value</td>
            <td>Default</td>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>left</td>
            <td><code>Number</code></td>
            <td>0</td>
        </tr>
        <tr>
            <td>top</td>
            <td><code>Number</code></td>
            <td>0</td>
        </tr>
        </tbody>
    </table>
    <h4>Example</h4>
    <pre>{
    left: 13,
    top: 37
}</pre>
</div>
<div class="content-wrapper">
    <h2 id="items">Items</h2>
    <p>Items are what drives taggd. Without items, there&#39;s no way it would know 
	where to put the tags and popups. That&#39;s why, we need items.</p>
    <p>Items can be set with the following line, where <code>data</code> is an 
	array of <a href="#item">Item Objects</a>.</p>
    <pre>$( image ).taggd( &#39;items&#39;, data );</pre>
</div>
<div class="content-wrapper">
    <h3 id="item">Item Object</h3>
    <table>
        <thead>
        <tr>
            <td>Property</td>
            <td>Description</td>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td><code>Float</code> x</td>
            <td>X position of the tag (and popup)</td>
        </tr>
        <tr>
            <td><code>Float</code> y</td>
            <td>Y position of the tag (and popup)</td>
        </tr>
        <tr>
            <td><code>String</code> text</td>
            <td>Optional. Set&#39;s the text of the popup. If omitted, there will be 
			no popup.</td>
        </tr>
        </tbody>
    </table>
    <p>The <code>x</code> and <code>y</code> property can be in a scale from 0 
	to 1, or a number in pixels based on the image&#39;s dimensions. Both are 
	scalable.</p>
    <p>This object also accepts custom properties, that can be read using a <a href="#handler">
	Handler</a>.</p>
    <h4>Example</h4>
    <pre>{
    x: 0.5,
    y: 0.5,
    text: &#39;Popup text&#39;
}</pre>
</div>
    <div id="demo-0">
    <img class="taggd" src="img/demo-0.jpg" alt="photo" />
    <div class="content-wrapper">
        <h3>Settings</h3>
                <pre>{
    align: {
        y: &#39;bottom&#39;
    },
    offset: {
        top: -15
    },
    handlers: {
        mouseenter: &#39;show&#39;,
        mouseleave: &#39;hide&#39;
    }
}</pre>
        <h3>Items</h3>
                <pre>[
    { x: 1099,  y: 220,  text: &#39;Dave&#39;   }, // pixel-based
    { x: 0.431, y: 0.33, text: &#39;Phil&#39;   }, // scale (0 - 1)
    { x: 0.468, y: 0.28, text: &#39;Steven&#39; }
]</pre>
    </div>
    <script type="text/javascript">
        data.push([
            { x: 0.572, y: 0.343, text: 'Dave' },
            { x: 0.431, y: 0.33, text: 'Phil' },
            { x: 0.468, y: 0.28, text: 'Steven' }
        ]);
        settings.push({
            align: { 'y': 'bottom' },
            offset: { 'top': -15 },
            'handlers': {
                'mouseenter': 'show',
                'mouseleave': 'hide'
            }
        });
    </script>
</div>
<div id="demo-1">
    <img class="taggd" src="img/demo-1.jpg" alt="photo" />
    <div class="content-wrapper">
        <h3>Settings</h3>
            <pre>{
    align: {
        y: &#39;top&#39;
    },
    offset: {
        top: 15
    },
    handlers: {
        click: &#39;toggle&#39;
    }
}</pre>
        <h3>Items</h3>
            <pre>[
    { x: 0.62, y: 0.7, text: &#39;Rope&#39;             },
    { x: 0.51, y: 0.5, text: &#39;Bird&#39;             },
    { x: 0.40, y: 0.3, text: &#39;Water, obviously&#39; }
]</pre>
    </div>
    <script type="text/javascript">
        data.push([
            { x: 0.62, y: 0.7, text: 'Rope' },
            { x: 0.51, y: 0.5, text: 'Bird' },
            { x: 0.40, y: 0.3, text: 'Water, obviously' }
        ]);
        settings.push({
            align: { 'y': 'top' },
            offset: { 'top': 15 },
            'handlers': {
                'click': 'toggle'
            }
        });
    </script>
</div>
<div id="demo-2">
    <img class="taggd" src="img/demo-2.jpg" alt="photo" />
    <div class="content-wrapper">
        <h3>Settings</h3>
            <pre>{
    align: {
        x: &#39;right&#39;
    },
    offset: {
        left: -15
    },
    handlers: {
        click: &#39;show&#39;,
        mouseleave: &#39;hide&#39;
    }
}</pre>
        <h3>Items</h3>
            <pre>[
    { x: 0.415, y: 0.343, text: &#39;Leaf&#39;                   },
    { x: 0.25,  y: 0.33,  text: &#39;More water&#39;             },
    { x: 0.8,   y: 0.1,   text: &#39;This used to be a tree&#39; }
]</pre>
    </div>
    <script type="text/javascript">
        data.push([
            { x: 0.415, y: 0.343, text: 'Leaf' },
            { x: 0.25, y: 0.33, text: 'More water' },
            { x: 0.8, y: 0.1, text: 'This used to be a tree' }
        ]);
        settings.push({
            align: { 'x': 'right' },
            offset: { 'left': -15 },
            'handlers': {
                'click': 'show',
                'mouseleave': 'hide'
            }
        });
    </script>
</div>
<div id="demo-3">
    <img class="taggd" src="img/demo-3.jpg" alt="photo" />
    <div class="content-wrapper">
        <h3>Settings</h3>
            <pre>{
    align: {
        y: &#39;bottom&#39;
    },
    offset: {
        top: -12
    },
    handlers: {
        click: function( e ) {
            var wiki = &#39;http://en.wikipedia.org/wiki/&#39; + e.data.uri;
            window.open( wiki, &#39;_blank&#39; );
        },
        mouseenter: &#39;show&#39;,
        mouseleave: &#39;hide&#39;
    }
}</pre>
        <h3>Items</h3>
            <pre>[
    { x: 0.1,  y: 0.54, text: &#39;Auto Rickshaw&#39;,      uri: &#39;Auto_rickshaw&#39;              },
    { x: 0.49, y: 0.57, text: &#39;Registration Plate&#39;, uri: &#39;Vehicle_registration_plate&#39; },
    { x: 0.38, y: 0.9,  text: &#39;Lighting&#39;,           uri: &#39;Automotive_lighting&#39;        }
]</pre>
    </div>
    <script type="text/javascript">
        data.push([
            { x: 0.1, y: 0.54, text: 'Auto Rickshaw', uri: 'Auto_rickshaw' },
            { x: 0.49, y: 0.57, text: 'Registration Plate', uri: 'Vehicle_registration_plate' },
            { x: 0.38, y: 0.9, text: 'Lighting', uri: 'Automotive_lighting' }
        ]);
        settings.push({
            'align': { 'y': 'bottom' },
            'offset': { 'top': -12 },
            'handlers': {
                'click': function(e) {
                    var wiki = 'http://en.wikipedia.org/wiki/' + e.data.uri;
                    window.open(wiki, '_blank');
                },
                mouseenter: 'show',
                mouseleave: 'hide'
            }
        });
    </script>
</div>
</div>
<div style="text-align:center;clear:both">
</div>



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册


热门标签: 瀑布流 收藏 预览 自适应页面大小 响应式区块列表布局 摇摆 烟花 清单样式 照相机 注释 下划线 结构图 鼠标悬停 条形码 弹幕 画板 朋友圈样式 红包 css绘制样式 支付 图文布局 右键菜单 图片全屏 文字标签 二维码 文字提示框 文字全屏 彩色文字 地图 提示框/弹出层 360全景 文字闪烁 计算器 layer 打字机 计时器 lightbox 文字列表 桌面 跳转 Tooltip工具提示框 文字弹幕 步骤 浮动提示框 文字高亮 键盘 html5弹窗动画 签到 分享 点赞 投票 雪花 打印 答题 震动 图表 鼠标滑过 抽奖 表情 qq空间 头像截图 星星打分评分 编辑器 播放器 电子杂志 排行榜 分页翻页 排序 表格隔行变色 table表格 进度条 多功能 文字叠加 文字拖动 文字提示框 文字收缩展开 文字放大缩小 文字翻转旋转 文字淡出淡进 文字全屏 文字延迟加载 360全景 html5文字动画 文字滚动 文字滑动 文字切换 弹出层拖动 窗口提示框 滑动星星打分 全屏焦点图 图片文字 文字导航菜单 全屏切换 宽屏全屏满屏 文字 其他更多

×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到