这是一个比较简单实用的菜单,最重要的是他不需要引用jQuery库。菜单在垂直方向上能做到自适应,当主菜单靠近顶部,子菜单将会在下面,当主菜单靠近底部,子菜单在上面。运用Modernizr的触摸检测功能,我们可以让子菜单的响应在pc上是hover,而在触摸设备上是点击。例子中还示范了如何在宽度比较窄的情况下如何调整布局。分享一个最好用的UI前端框架!
html代码:
- <ul id="cbp-tm-menu" class="cbp-tm-menu">
- <li>
- <a href="#">Home</a>
- </li>
- <li>
- <a href="#">Veggie made</a>
- <ul class="cbp-tm-submenu">
- <li><a href="#" class="cbp-tm-icon-archive">Sorrel desert</a></li>
- <li><a href="#" class="cbp-tm-icon-cog">Raisin kakadu</a></li>
- <li><a href="#" class="cbp-tm-icon-location">Plum salsify</a></li>
- <li><a href="#" class="cbp-tm-icon-users">Bok choy celtuce</a></li>
- <li><a href="#" class="cbp-tm-icon-earth">Onion endive</a></li>
- <li><a href="#" class="cbp-tm-icon-location">Bitterleaf</a></li>
- <li><a href="#" class="cbp-tm-icon-mobile">Sea lettuce</a></li>
- </ul>
- </li>
- <li>
- <a href="#">Pepper tatsoi</a>
- <ul class="cbp-tm-submenu">
- <li><a href="#" class="cbp-tm-icon-archive">Brussels sprout</a></li>
- <li><a href="#" class="cbp-tm-icon-cog">Kakadu lemon</a></li>
- <li><a href="#" class="cbp-tm-icon-link">Juice green</a></li>
- <li><a href="#" class="cbp-tm-icon-users">Wine fruit</a></li>
- <li><a href="#" class="cbp-tm-icon-earth">Garlic mint</a></li>
- <li><a href="#" class="cbp-tm-icon-location">Zucchini garnish</a></li>
- <li><a href="#" class="cbp-tm-icon-mobile">Sea lettuce</a></li>
- </ul>
- </li>
- <li>
- <a href="#">Sweet melon</a>
- <ul class="cbp-tm-submenu">
- <li><a href="#" class="cbp-tm-icon-screen">Sorrel desert</a></li>
- <li><a href="#" class="cbp-tm-icon-mail">Raisin kakadu</a></li>
- <li><a href="#" class="cbp-tm-icon-contract">Plum salsify</a></li>
- <li><a href="#" class="cbp-tm-icon-pencil">Bok choy celtuce</a></li>
- <li><a href="#" class="cbp-tm-icon-article">Onion endive</a></li>
- <li><a href="#" class="cbp-tm-icon-clock">Bitterleaf</a></li>
- </ul>
- </li>
- <a style="font-family: Arial; white-space: normal; background-color: #ffffff;" target="_blank" href="/topic/1132907">前端UI分享</a>
- </ul>
css代码分享一个最好用的UI前端框架!
- /* Iconfont made with icomoon.com */
- @font-face {
- font-family: 'cbp-tmicons';
- src:url('../fonts/tmicons/cbp-tmicons.eot');
- src:url('../fonts/tmicons/cbp-tmicons.eot?#iefix') format('embedded-opentype'),
- url('../fonts/tmicons/cbp-tmicons.woff') format('woff'),
- url('../fonts/tmicons/cbp-tmicons.ttf') format('truetype'),
- url('../fonts/tmicons/cbp-tmicons.svg#cbp-tmicons') format('svg');
- font-weight: normal;
- font-style: normal;
- }
- /* reset list style */
- .cbp-tm-menu,
- .cbp-tm-menu ul {
- list-style: none;
- }
- /* set menu position; change here to set to relative or float, etc. */
- .cbp-tm-menu {
- display: block;
- position: absolute;
- z-index: 1000;
- bottom: 0;
- width: 100%;
- background: #47a3da;
- text-align: right;
- padding: 0 2em;
- margin: 0;
- text-transform: capitalize;
- }
- /* first level menu items */
- .cbp-tm-menu > li {
- display: inline-block;
- margin: 0 2.6em;
- position: relative;
- }
- .cbp-tm-menu > li > a {
- line-height: 4em;
- padding: 0 0.3em;
- font-size: 1.2em;
- display: block;
- color: #fff;
- }
- <a style="font-family: Arial;" target="_blank" href="/topic/1132907">前端UI分享</a>
- .no-touch .cbp-tm-menu > li > a:hover,
- .no-touch .cbp-tm-menu > li > a:active {
- color: #02639d;
- }
- /* sumbenu with transitions */
- .cbp-tm-submenu {
- position: absolute;
- display: block;
- visibility: hidden;
- opacity: 0;
- padding: 0;
- text-align: left;
- pointer-events: none;
- -webkit-transition: visibility 0s, opacity 0s;
- -moz-transition: visibility 0s, opacity 0s;
- transition: visibility 0s, opacity 0s;
- }
- .cbp-tm-show .cbp-tm-submenu {
- width: 16em;
- left: 50%;
- margin: 0 0 0 -8em;
- opacity: 1;
- visibility: visible;
- pointer-events: auto;
- -webkit-transition: visibility 0s, opacity 0.3s;
- -moz-transition: visibility 0s, opacity 0.3s;
- transition: visibility 0s, opacity 0.3s;
- }
- .cbp-tm-show-above .cbp-tm-submenu {
- bottom: 100%;
- padding-bottom: 10px;
- }
- .cbp-tm-show-below .cbp-tm-submenu {
- top: 100%;
- padding-top: 10px;
- }
- /* extreme cases: not enough space on the sides */
- .cbp-tm-nospace-right .cbp-tm-submenu {
- right: 0;
- left: auto;
- }
- .cbp-tm-nospace-left .cbp-tm-submenu {
- left: 0;
- }
- <a style="font-family: Arial;" target="_blank" href="/topic/1132907">前端UI分享</a>
- /* last menu item has to fit on the screen */
- .cbp-tm-menu > li:last-child .cbp-tm-submenu {
- right: 0;
- }
- /*
- arrow: depending on where the menu will be shown, we set
- the right position for the arrow
- */
- .cbp-tm-submenu:after {
- border: solid transparent;
- content: " ";
- height: 0;
- width: 0;
- position: absolute;
- pointer-events: none;
- }
- .cbp-tm-show-above .cbp-tm-submenu:after {
- top: 100%;
- margin-top: -10px;
- }
- .cbp-tm-show-below .cbp-tm-submenu:after {
- bottom: 100%;
- margin-bottom: -10px;
- }
- .cbp-tm-submenu:after {
- border-color: transparent;
- border-width: 16px;
- margin-left: -16px;
- left: 50%;
- }
- .cbp-tm-show-above .cbp-tm-submenu:after {
- border-top-color: #fff;
- }
- .cbp-tm-show-below .cbp-tm-submenu:after {
- border-bottom-color: #fff;
- }
- .cbp-tm-submenu > li {
- display: block;
- background: #fff;
- }
- .cbp-tm-submenu > li > a {
- padding: 5px 2.3em 5px 0.6em; /* top/bottom paddings in 'em' cause a tiny "jump" in Chrome on Win */
- display: block;
- font-size: 1.2em;
- position: relative;
- color: #47a3da;
- border: 4px solid #fff;
- -webkit-transition: all 0.2s;
- -moz-transition: all 0.2s;
- transition: all 0.2s;
- }
- .no-touch .cbp-tm-submenu > li > a:hover,
- .no-touch .cbp-tm-submenu > li > a:active {
- color: #fff;
- background: #47a3da;
- }
- /* the icons (main level menu icon and sublevel icons) */
- .cbp-tm-submenu li a:before,
- .cbp-tm-menu > li > a:before {
- font-family: 'cbp-tmicons';
- speak: none;
- font-style: normal;
- font-weight: normal;
- font-variant: normal;
- text-transform: none;
- line-height: 1;
- vertical-align: middle;
- margin-right: 0.6em;
- -webkit-font-smoothing: antialiased;
- }
- <a style="font-family: Arial;" target="_blank" href="/topic/1132907">前端UI分享</a>
- .cbp-tm-submenu li a:before {
- position: absolute;
- top: 50%;
- margin-top: -0.5em;
- right: 0.5em;
- }
- .cbp-tm-menu > li > a:not(:only-child):before {
- content: "\f0c9";
- font-size: 60%;
- opacity: 0.3;
- }
- .cbp-tm-icon-archive:before {
- content: "\e002";
- }
- .cbp-tm-icon-cog:before {
- content: "\e003";
- }
- .cbp-tm-icon-users:before {
- content: "\e004";
- }
- .cbp-tm-icon-earth:before {
- content: "\e005";
- }
- .cbp-tm-icon-location:before {
- content: "\e006";
- }
- .cbp-tm-icon-mobile:before {
- content: "\e007";
- }
- .cbp-tm-icon-screen:before {
- content: "\e008";
- }
- .cbp-tm-icon-mail:before {
- content: "\e009";
- }
- .cbp-tm-icon-contract:before {
- content: "\e00a";
- }
- .cbp-tm-icon-pencil:before {
- content: "\e00b";
- }
- .cbp-tm-icon-article:before {
- content: "\e00c";
- }
- .cbp-tm-icon-clock:before {
- content: "\e00d";
- }
- .cbp-tm-icon-videos:before {
- content: "\e00e";
- }
- .cbp-tm-icon-pictures:before {
- content: "\e00f";
- }
- .cbp-tm-icon-link:before {
- content: "\e010";
- }
- .cbp-tm-icon-refresh:before {
- content: "\e011";
- }
- .cbp-tm-icon-help:before {
- content: "\e012";
- }
- /* Media Queries */
- @media screen and (max-width: 55.6875em) {
- .cbp-tm-menu {
- font-size: 80%;
- }
- }
- <a style="font-family: Arial;" target="_blank" href="/topic/1132907">前端UI分享</a>
- @media screen and (max-height: 25.25em), screen and (max-width: 44.3125em) {
- .cbp-tm-menu {
- font-size: 100%;
- position: relative;
- text-align: center;
- padding: 0;
- top: auto;
- }
- .cbp-tm-menu > li {
- display: block;
- margin: 0;
- border-bottom: 4px solid #3793ca;
- }
- .cbp-tm-menu > li:first-child {
- border-top: 4px solid #3793ca;
- }
- li.cbp-tm-show > a,
- .no-touch .cbp-tm-menu > li > a:hover,
- .no-touch .cbp-tm-menu > li > a:active {
- color: #fff;
- background: #02639d;
- }
- .cbp-tm-submenu {
- position: relative;
- display: none;
- width: 100%;
- }
- .cbp-tm-submenu > li {
- padding: 0;
- }
- .cbp-tm-submenu > li > a {
- padding: 0.6em 2.3em 0.6em 0.6em;
- border: none;
- border-bottom: 2px solid #6fbbe9;
- }
- .cbp-tm-submenu:after {
- display: none;
- }
- .cbp-tm-menu .cbp-tm-show .cbp-tm-submenu {
- display: block;
- width: 100%;
- left: 0;
- margin: 0;
- padding: 0;
- bottom: auto;
- top: auto;
- }
- }
javascript代码
- /**
- * cbpTooltipMenu.js v1.0.0
- * http://www.codrops.com
- *
- * Licensed under the MIT license.
- * http://www.opensource.org/licenses/mit-license.php
- *
- * Copyright 2013, Codrops
- * http://www.codrops.com
- */
- ;( function( window ) {
- 'use strict';
- var document = window.document,
- docElem = document.documentElement;
- function extend( a, b ) {
- for( var key in b ) {
- if( b.hasOwnProperty( key ) ) {
- a[key] = b[key];
- }
- }
- return a;
- }
- // from https://github.com/ryanve/response.js/blob/master/response.js
- function getViewportH() {
- var client = docElem['clientHeight'],
- inner = window['innerHeight'];
- if( client < inner )
- return inner;
- else
- return client;
- }
- // http://stackoverflow.com/a/11396681/989439
- function getOffset( el ) {
- return el.getBoundingClientRect();
- }
- // http://snipplr.com/view.php?codeview&id=5259
- function isMouseLeaveOrEnter(e, handler) {
- if (e.type != 'mouseout' && e.type != 'mouseover') return false;
- var reltg = e.relatedTarget ? e.relatedTarget :
- e.type == 'mouseout' ? e.toElement : e.fromElement;
- while (reltg && reltg != handler) reltg = reltg.parentNode;
- return (reltg != handler);
- }
- function cbpTooltipMenu( el, options ) {
- this.el = el;
- this.options = extend( this.defaults, options );
- this._init();
- }
- <a target="_blank" href="/topic/1132907">前端UI分享</a>
- cbpTooltipMenu.prototype = {
- defaults : {
- // add a timeout to avoid the menu to open instantly
- delayMenu : 100
- },
- _init : function() {
- this.touch = Modernizr.touch;
- this.menuItems = document.querySelectorAll( '#' + this.el.id + ' > li' );
- this._initEvents();
- },
- _initEvents : function() {
- var self = this;
- Array.prototype.slice.call( this.menuItems ).forEach( function( el, i ) {
- var trigger = el.querySelector( 'a' );
- if( self.touch ) {
- trigger.addEventListener( 'click', function( ev ) { self._handleClick( this, ev ); } );
- }
- else {
- trigger.addEventListener( 'click', function( ev ) {
- if( this.parentNode.querySelector( 'ul.cbp-tm-submenu' ) ) {
- ev.preventDefault();
- }
- } );
- el.addEventListener( 'mouseover', function(ev) { if( isMouseLeaveOrEnter( ev, this ) ) self._openMenu( this ); } );
- el.addEventListener( 'mouseout', function(ev) { if( isMouseLeaveOrEnter( ev, this ) ) self._closeMenu( this ); } );
- }
- } );
- },
- _openMenu : function( el ) {
- var self = this;
- clearTimeout( this.omtimeout );
- this.omtimeout = setTimeout( function() {
- var submenu = el.querySelector( 'ul.cbp-tm-submenu' );
- if( submenu ) {
- el.className = 'cbp-tm-show';
- if( self._positionMenu( el ) === 'top' ) {
- el.className += ' cbp-tm-show-above';
- }
- else {
- el.className += ' cbp-tm-show-below';
- }
- }
- }, this.touch ? 0 : this.options.delayMenu );
- },
- _closeMenu : function( el ) {
- clearTimeout( this.omtimeout );
- var submenu = el.querySelector( 'ul.cbp-tm-submenu' );
- if( submenu ) {
- // based on https://github.com/desandro/classie/blob/master/classie.js
- el.className = el.className.replace(new RegExp("(^|\\s+)" + "cbp-tm-show" + "(\\s+|$)"), ' ');
- el.className = el.className.replace(new RegExp("(^|\\s+)" + "cbp-tm-show-below" + "(\\s+|$)"), ' ');
- el.className = el.className.replace(new RegExp("(^|\\s+)" + "cbp-tm-show-above" + "(\\s+|$)"), ' ');
- }
- },
- _handleClick : function( el, ev ) {
- var item = el.parentNode,
- items = Array.prototype.slice.call( this.menuItems ),
- submenu = item.querySelector( 'ul.cbp-tm-submenu' )
- // first close any opened one..
- if( this.current && items.indexOf( item ) !== this.current ) {
- this._closeMenu( this.el.children[ this.current ] );
- this.el.children[ this.current ].querySelector( 'ul.cbp-tm-submenu' ).setAttribute( 'data-open', 'false' );
- }
- if( submenu ) {
- ev.preventDefault();
- var isOpen = submenu.getAttribute( 'data-open' );
- if( isOpen === 'true' ) {
- this._closeMenu( item );
- submenu.setAttribute( 'data-open', 'false' );
- }
- else {
- this._openMenu( item );
- this.current = items.indexOf( item );
- submenu.setAttribute( 'data-open', 'true' );
- }
- }
- },
- arget="_blank" href="/topic/1132907">前端UI分享</a>
- _positionMenu : function( el ) {
- // checking where's more space left in the viewport: above or below the element
- var vH = getViewportH(),
- ot = getOffset(el),
- spaceUp = ot.top ,
- spaceDown = vH - spaceUp - el.offsetHeight;
- return ( spaceDown <= spaceUp ? 'top' : 'bottom' );
- }
- }
- // add to global namespace
- window.cbpTooltipMenu = cbpTooltipMenu;
- window );
相关推荐
以上这些知识点共同构成了实现垂直方向自适应三角提示菜单的核心要素,涵盖了从HTML结构到CSS样式再到JavaScript逻辑的完整实现路径。通过这些知识点的掌握,开发者可以灵活地创建出既美观又实用的菜单效果。
本教程将详细介绍如何使用CSS3来创建一个自适应的、带有角度和边框的对话气泡,同时支持自定义背景色,实现更高效、更灵活的设计。 首先,我们需要创建HTML结构,为对话气泡提供基本的容器。一个简单的示例是: ``...
在这个模板中,CSS3被用来创建复杂的三角形形状,通过控制边框宽度和颜色实现,还可能用于实现页面元素的平滑过渡和动画效果。 2. **三角形设计**:在CSS3中,通过设置元素的边框宽度和颜色,可以巧妙地创建出不同...
在CSS3的世界里,设计独特的形状不再依赖于复杂的图片或者JavaScript插件,而是可以通过纯CSS实现。本主题探讨的是如何利用CSS3技术创建一个自适应的六边形列表。六边形列表是一种创新的设计方式,它能为网页增添...
综合来看,这个压缩包包含的内容是网页开发的黄金三角——HTML、CSS和JavaScript的实战应用,还有H5模板和自适应的UI组件,为开发者提供了丰富的学习材料和实际项目的起点。无论是初学者还是经验丰富的开发者,都...
【标题解析】 “NO JS css3 Tab页签切换效果选项卡...总的来说,这个资源提供了一种完全使用CSS3实现的选项卡切换效果,对于希望学习CSS3动态效果或者避免使用JavaScript的开发者来说,是一个很好的学习和实践素材。
3. 图片轮播(Carousel):通过CSS和JavaScript实现图片自动切换的组件。 4. 悬停效果(Hover Effects):如按钮、链接的悬停变色、放大等效果。 5. 响应式设计(Responsive Design):根据屏幕尺寸调整布局和元素...
Bootstrap是一个流行的开源前端框架,它包含了一系列预设的CSS样式、JavaScript插件和HTML组件,极大地简化了响应式网页开发的过程。在这款模板中,Bootstrap被用来构建一个整站的响应式布局,这意味着无论用户是在...
【CSS 居中】:CSS提供了多种居中方法,包括水平居中和垂直居中。水平居中对行内元素可以使用`text-align: center`,对块级元素可以使用`margin: 0 auto`或`position: absolute`结合`left: 50%`和`transform: ...
- 用div+css实现固定宽度与自适应宽度布局的方法。 - display: inline-block时间隙产生的原因及处理方式。 - overflow属性的不同值的作用。 - 通过CSS去掉移动端默认样式的方法。 - CSS样式初始化的目的和好处...
1. **居中布局**:多种方法实现元素的水平和垂直居中,如margin auto、text-align center、display: table-cell、绝对定位配合transform、BFC等。 2. **BFC(Block Formatting Context)**:BFC可以防止内部浮动...
在IT行业中,多边形导航是一种常见的网页设计技术,它通过使用HTML、CSS以及可能的JavaScript来创建具有吸引力和互动性的导航菜单。这种导航通常利用几何形状,特别是多边形,来增强用户界面的视觉效果,使网站看...
六边形网格布局的实现通常涉及JavaScript,以动态调整每个六边形的大小和位置,以适应不同的屏幕尺寸和设备。例如,使用媒体查询(`media queries`)来响应式布局,确保在各种设备上都有良好的显示效果。 此外,`...
### CSS高频笔试题精讲知识点解析 ...以上是对CSS高频笔试题目的精讲,包含了常见的单位、居中技巧、响应式布局、0.5px线实现、Sass基础知识、弹性布局以及BFC的相关知识,希望能帮助大家更好地理解和掌握CSS。
通过查看这些文件,我们可以看到具体的实现细节,如如何定义Vue组件,如何编写CSS来实现自适应布局,以及如何在JavaScript中处理和绘制数据。 总的来说,"VUE.JS自适应蛇形曲线数据代码"项目涵盖了Vue.js组件化开发...
总之,这个项目展示了如何综合运用JavaScript、HTML5和CSS3实现一个引人入胜的3D立体照片墙,同时涵盖了前端开发的多个重要方面,包括动态效果、布局、响应式设计以及性能优化等。通过学习和理解这个项目,开发者...
总结起来,实现纵向横向菜单的关键在于理解jQuery的选择器、事件和动画方法,以及结合CSS来控制布局和样式。通过这样的组合,我们可以创建出富有动态效果、用户体验良好的交互式菜单。在实际项目中,可以根据需求...
5. CSS中的居中方法包括了水平居中和垂直居中,使用的技术如margin: 0 auto、Flexbox布局等。 6. CSS选择器的优先级是由其特殊性决定的,特殊性由选择器的类型和数量决定。 7. 清除浮动的目的是为了防止浮动元素...
此外,还可以用到三角函数(如sine和cosine)来实现更复杂的运动轨迹。 8. 性能优化: 对于大量的粒子,性能优化至关重要。开发者可能采用批量绘制粒子,减少不必要的重绘,或者使用对象池技术来复用粒子,避免...
13. **用CSS画三角形**:通过调整边框颜色和透明度实现,通常用于制作箭头。 14. **字体奇偶数选择**:通常使用偶数字体大小,便于布局对齐和像素转换,提升视觉效果。 15. **CSS Reset**:重置浏览器默认样式,如...