JS and CSS 一下代码都是基于 jQuery、Semantic Ui、Layer、Vue 来写的:
1 2 3 4 5 <link rel ="stylesheet" href ="http://cdn.staticfile.org/semantic-ui/2.2.7/semantic.min.css" > <script src ="http://cdn.bootcss.com/jquery/1.9.1/jquery.min.js" > </script > <script src ="http://cdn.staticfile.org/semantic-ui/2.2.7/semantic.min.js" > </script > <script src ="http://cdn.staticfile.org/vue/2.0.3/vue.js" > </script > <script src ="http://cdn.staticfile.org/layer/2.3/layer.js" > </script >
Dropdown 1 2 3 4 5 6 7 8 9 10 11 <div class ="ui floating labeled icon dropdown button" > <input type ="hidden" > <i class ="world icon" > </i > <span class ="text" > 选择地区</span > <div class ="menu" > <div class ="item" data-value ="1" > 北京</div > <div class ="item" data-value ="2" > 上海</div > <div class ="item" data-value ="3" > 天津</div > <div class ="item" data-value ="4" > 湖北</div > </div > </div >
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 $('.dropdown' ).dropdown(); $('.dropdown' ).dropdown({onChange : function (value, text, $choice ) { layer.msg(value + " : " + text); }}); $('.dropdown' ).dropdown('set selected' , 2 ); $('.dropdown' ).dropdown('get value' ); $('.dropdown' ).dropdown('get text' );
Card
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 <!DOCTYPE html > <html > <head > <meta charset ="utf-8" > <title > </title > <link rel ="stylesheet" href ="http://cdn.staticfile.org/semantic-ui/2.2.7/semantic.min.css" > <script src ="http://cdn.bootcss.com/jquery/1.9.1/jquery.min.js" > </script > <script src ="http://cdn.staticfile.org/semantic-ui/2.2.7/semantic.min.js" > </script > <script src ="http://cdn.staticfile.org/vue/2.0.3/vue.js" > </script > <script src ="http://cdn.staticfile.org/layer/2.3/layer.js" > </script > <style media ="screen" > body { padding : 20px ; } .ui .card .dimmer { cursor : default; border-top-left-radius : .28571429rem ; border-top-right-radius : .28571429rem ; } </style > </head > <body > <div class ="ui card" > <div class ="dimmable image" > <div class ="ui dimmer" > <div class ="content" > <div class ="center" > 焚我残躯,熊熊圣火,生亦何欢,死亦何苦?为善除恶,唯光明故。喜乐悲愁,皆归尘土。怜我世人,忧患实多!</div > </div > </div > <img src ="http://omqpd0pt4.bkt.clouddn.com/steve.jpg" > </div > <div class ="content" > <div class ="header" > Matt Giampietro</div > <div class ="meta" > <a > Friends</a > </div > <div class ="description" > Matthew is an interior designer living in New York. </div > </div > <div class ="extra content" > <span > <i class ="tags icon" > </i > </span > <span > <i class ="user icon" > </i > 75 Friends</span > <span class ="right floated" > Joined in 2013</span > </div > </div > <script > $('.dimmable' ).dimmer({on : 'hover' }); </script > </body > </html >
使用 data-tooltip ,不需要 JS,Popup 的位置不会自动变化:
1 2 3 4 5 6 7 8 9 <body > <div class ="ui icon button" data-tooltip ="Add users to your feed" > <i class ="add icon" > </i > </div > <div class ="ui icon button" data-tooltip ="Add users to your feed" data-position ="bottom left" data-inverted ="" > <i class ="minus icon" > </i > </div > </body >
使用 data-content ,需要执行 popup() 函数,Popup 的位置能够自适应:
1 2 3 4 5 6 7 8 9 10 11 12 <body > <span class ="with-popup" data-content ="知识点标签" > <i class ="tags icon" > </i > </span > <script > $('.with-popup' ).popup(); $('.with-popup' ).popup({ position : 'bottom left' }); $('.with-popup' ).popup({ position : 'bottom left' , offset : -12 }); </script > </body >
自定义 Popup,需要执行 popup() 函数,Popup 的内容和触发者不在一起:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <body > <div class ="ui button" id ="show-popup-button" > Show custom popup</div > <span id ="show-popup-span" > <i class ="tags icon" > </i > Google</span > <div class ="ui custom popup transition hidden" > I'm not on the same level as the <div class ="ui grey button" > Button</div > , but i can still be found. </div > <script > $('#show-popup-button, #show-popup-span' ).popup({ position : 'bottom left' , popup : $('.custom.popup' ), on : 'hover' }); </script > </body >
微调 Popup 的位置
1 2 $('.with-popup' ).popup({ position : 'bottom left' , offset : -12 });