仿51job.com城市选择框特效

本文介绍了一个模仿51job网站的城市选择框特效实现案例。通过HTML、CSS及JavaScript实现了可拖动的选择框,支持多选并展示已选城市。文章详细展示了特效的前端代码实现。


  1. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <htmlxmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
  5. <title>仿51job.com城市选择框特效</title>
  6. <styletype="text/css">
  7. <!--
  8. body{padding-top:50px;font-size:12px;}
  9. h2{margin:0px;padding:0px;font-size:12px;font-weight:bold;}
  10. .bton{border:1pxsolid#CCC;background:#DDD;}
  11. .cont{padding:10px;}
  12. #main{width:400px;margin:0pxauto;}
  13. #selectItem{background:#FFF;position:absolute;top:0px;left:center;border:1pxsolid#000;overflow:hidden;margin-top:10px;width:400px;z-index:2;}
  14. #preview{margin:1px;border:1pxsolid#CCC;}
  15. #result{border:1pxsolid#CCC;margin-top:10px;}
  16. .tit{line-height:20px;height:20px;margin:1px;padding-left:10px;}
  17. .bgc_ccc{background:#CCC;}
  18. .bgc_eee{background:#eee;}
  19. .c_999{color:#999}
  20. .pointer{cursor:pointer;}
  21. .left{float:left;}
  22. .right{float:right;}
  23. .cls{clear:both;font-size:0px;height:0px;overflow:hidden;}
  24. #bg{background:#CCC;filter:alpha(opacity=70);opacity:0.7;width:100%;;position:absolute;left:0px;top:0px;display:none;z-index:1;}
  25. .hidden{display:none;}
  26. .move{cursor:move;}
  27. -->
  28. </style>
  29. </head>
  30. <body>
  31. <divid="main">
  32. <inputname="button"type="button"class="btonpointer"value="请选择"onclick="openBg(1);openSelect(1)"/>
  33. <divid="result">
  34. <divclass="titbgc_eee">
  35. <h2>您已选择的城市汇总</h2>
  36. </div>
  37. <divclass="cont"id="makeSureItem">
  38. </div>
  39. </div>
  40. </div>
  41. <divid="bg">
  42. </div>
  43. <divid="selectItem"class="hidden">
  44. <divclass="titbgc_cccmove"onmousedown="drag(event,this)">
  45. <h2class="left">请选择城市</h2>
  46. <spanclass="pointerright"onclick="openBg(0);openSelect(0);">[取消]</span>
  47. <spanclass="pointerright"onclick="makeSure();">[确定]</span>
  48. </div>
  49. <divclass="cls"></div>
  50. <divclass="cont">
  51. <divid="selectSub">
  52. <divid="c00">
  53. <inputtype="checkbox"name="ck00"onclick="addPreItem()"value="北京"/>北京
  54. <inputtype="checkbox"name="ck00"onclick="addPreItem()"value="福建"/>福建
  55. <inputtype="checkbox"name="ck00"onclick="addPreItem()"value="四川"/>四川
  56. <inputtype="checkbox"name="ck00"onclick="addPreItem()"value="江苏"/>江苏
  57. </div>
  58. <divid="c01">
  59. <inputtype="checkbox"name="ck01"onclick="addPreItem()"value="上海"/>上海
  60. <inputtype="checkbox"name="ck01"onclick="addPreItem()"value="云南"/>云南
  61. <inputtype="checkbox"name="ck01"onclick="addPreItem()"value="贵州"/>贵州
  62. </div>
  63. <divid="c02">
  64. <inputtype="checkbox"name="ck01"onclick="addPreItem()"value="黑龙江"/>黑龙江
  65. <inputtype="checkbox"name="ck01"onclick="addPreItem()"value="吉林"/>吉林
  66. <inputtype="checkbox"name="ck01"onclick="addPreItem()"value="辽宁"/>辽宁
  67. </div>
  68. <divid="c03">
  69. <inputtype="checkbox"name="ck01"onclick="addPreItem()"value="美国"/>美国
  70. <inputtype="checkbox"name="ck01"onclick="addPreItem()"value="阿富汗"/>阿富汗
  71. <inputtype="checkbox"name="ck01"onclick="addPreItem()"value="日本"/>日本
  72. </div>
  73. </div>
  74. </div>
  75. <divid="preview">
  76. <divclass="titbgc_eeec_999">
  77. <h2>您已选择的城市</h2>
  78. </div>
  79. <divclass="cont"id="previewItem">
  80. </div>
  81. </div>
  82. </div>
  83. <scripttype="text/javascript">
  84. /*------使用说明-----*/
  85. /*
  86. 添加城市方法:
  87. 添加组:找到id是"selectSub"中select标签下,添加option标签value属性递增,找到id是"selectSub",按照原有格式添加div,其id属性递增
  88. 添加二级傅选矿选项
  89. 复制id是"selectSub"下任意input标签,粘贴在需要添加的位置。
  90. */
  91. vargrow=$("selectSub").getElementsByTagName("option").length;//组数
  92. varshowGrow=0;//已打开组
  93. varselectCount=0;//已选数量
  94. showSelect(showGrow);
  95. varitems=$("selectSub").getElementsByTagName("input");
  96. //alert(maxItem);
  97. //varlenMax=2;
  98. //alert(1);
  99. function$(o){//获取对象
  100. if(typeof(o)=="string")
  101. returndocument.getElementById(o);
  102. returno;
  103. }
  104. functionopenBg(state){//遮照打开关闭控制
  105. if(state==1)
  106. {
  107. $("bg").style.display="block";
  108. varh=document.body.offsetHeight>document.documentElement.offsetHeight?document.body.offsetHeight:document.documentElement.offsetHeight;
  109. //alert(document.body.offsetHeight);
  110. //alert(document.documentElement.offsetHeight);
  111. $("bg").style.height=h+"px";
  112. }
  113. else
  114. {
  115. $("bg").style.display="none";
  116. }
  117. }
  118. functionopenSelect(state){//选择城市层关闭打开控制
  119. if(state==1)
  120. {
  121. $("selectItem").style.display="block";
  122. $("selectItem").style.left=($("bg").offsetWidth-$("selectItem").offsetWidth)/2+"px";
  123. $("selectItem").style.top=document.body.scrollTop+100+"px";
  124. }
  125. else
  126. {
  127. $("selectItem").style.display="none";
  128. }
  129. }
  130. functionshowSelect(id){
  131. for(vari=0;i<grow;i++)
  132. {
  133. $("c0"+i).style.display="none";
  134. }
  135. $("c0"+id).style.display="block";
  136. showGrow=id;
  137. }
  138. functionopen(id,state){//显示隐藏控制
  139. if(state==1)
  140. $(id).style.display="block";
  141. $(id).style.diaplay="none";
  142. }
  143. functionaddPreItem(){
  144. $("previewItem").innerHTML="";
  145. varlen =0;
  146. for(vari=0;i<items.length;i++)
  147. {
  148. if(items[i].checked==true)
  149. {
  150. //len++;
  151. //if(len>lenMax)
  152. //{
  153. //alert("不能超过"+lenMax+"个选项!")
  154. //returnfalse;
  155. //}
  156. varmes="<inputtype='checkbox'checked='true'value='"+items[i].value+"'onclick='copyItem(\"previewItem\",\"previewItem\");same(this);'>"+items[i].value;
  157. $("previewItem").innerHTML+=mes;
  158. //alert(items[i].value);
  159. }
  160. }
  161. }
  162. functionmakeSure(){
  163. //alert(1);
  164. //$("makeSureItem").innerHTML=$("previewItem").innerHTML;
  165. openBg(0);
  166. openSelect(0);
  167. copyItem("previewItem","makeSureItem")
  168. }
  169. functioncopyHTML(id1,id2){
  170. $(id2).innerHTML=$("id1").innerHTML;
  171. }
  172. functioncopyItem(id1,id2){
  173. varmes="";
  174. varitems2=$(id1).getElementsByTagName("input");
  175. for(vari=0;i<items2.length;i++)
  176. {
  177. if(items2[i].checked==true)
  178. {
  179. mes+="<inputtype='checkbox'checked='true'value='"+items2[i].value+"'onclick='copyItem(\""+id2+"\",\""+id1+"\");same(this);'>"+items2[i].value;
  180. }
  181. }
  182. $(id2).innerHTML="";
  183. $(id2).innerHTML+=mes;
  184. //alert($(id2).innerHTML);
  185. }
  186. functionsame(ck){
  187. for(vari=0;i<items.length;i++)
  188. {
  189. if(ck.value==items[i].value)
  190. {
  191. items[i].checked=ck.checked;
  192. }
  193. }
  194. }
  195. /*鼠标拖动*/
  196. varoDrag="";
  197. varox,oy,nx,ny,dy,dx;
  198. functiondrag(e,o){
  199. varee=e?e:event;
  200. varmouseD=document.all?1:0;
  201. if(e.button==mouseD)
  202. {
  203. ooDrag=o.parentNode;
  204. //alert(oDrag.id);
  205. ox=e.clientX;
  206. oy=e.clientY;
  207. }
  208. }
  209. functiondragPro(e){
  210. if(oDrag!="")
  211. {
  212. varee=e?e:event;
  213. //$(oDrag).style.left=$(oDrag).offsetLeft+"px";
  214. //$(oDrag).style.top=$(oDrag).offsetTop+"px";
  215. dx=parseInt($(oDrag).style.left);
  216. dy=parseInt($(oDrag).style.top);
  217. //dx=$(oDrag).offsetLeft;
  218. //dy=$(oDrag).offsetTop;
  219. nx=e.clientX;
  220. ny=e.clientY;
  221. $(oDrag).style.left=(dx+(nx-ox))+"px";
  222. $(oDrag).style.top=(dy+(ny-oy))+"px";
  223. ox=nx;
  224. oy=ny;
  225. }
  226. }
  227. document.onmouseup=function(){oDrag="";}
  228. document.onmousemove=function(event){dragPro(event);}
  229. </script>
  230. </body>
  231. </html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值