zcUI.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. $(function(){
  2. ui_radiobox();
  3. ui_checkbox();
  4. button_hover(".ui-button");
  5. button_hover(".ui_button");
  6. button_hover(".ui-small-button");
  7. button_hover(".ui-center-button");
  8. show_tip();
  9. init_gotop();
  10. });
  11. // 初始化单选框,该UI必为label,且内部需要有radio
  12. function ui_radiobox(){
  13. $(".ui_radiobox").each(function(){
  14. var img = $(this);
  15. var o = img.find("input[type='radio']");
  16. o.hide();
  17. var checked = $(o).attr("checked");
  18. img.addClass("common_rdo");
  19. img.attr("name",o.attr("name"));
  20. img.attr("checked",checked?true:false);
  21. img.css({"display":"inline-block"});
  22. if(checked){
  23. img.removeClass("common_rdo");
  24. img.removeClass("common_rdo_checked");
  25. img.addClass("common_rdo_checked");
  26. }
  27. else{
  28. img.removeClass("common_rdo");
  29. img.removeClass("common_rdo_checked");
  30. img.addClass("common_rdo");
  31. }
  32. });
  33. $(".ui_radiobox").hover(function(){
  34. var img = $(this);
  35. img.css("cursor","pointer");
  36. var o = img.find("input[type='radio']");
  37. var checked = o.attr("checked");
  38. if(!checked){
  39. $(this).addClass("common_rdo_hover");
  40. }
  41. },function(){
  42. $(this).removeClass("common_rdo_hover");
  43. });
  44. $(".ui_radiobox").find("input[type='radio']").bind("click",function(){
  45. return false;
  46. });
  47. $(".ui_radiobox").click(function(){
  48. var img = $(this);
  49. var o = img.find("input[type='radio']");
  50. var rel=img.attr("rel");
  51. checked = true;
  52. $(".ui_radiobox[rel='"+rel+"']").attr("checked",false);
  53. $(".ui_radiobox[rel='"+rel+"']").removeClass("common_rdo_hover");
  54. $(".ui_radiobox[rel='"+rel+"']").addClass("common_rdo");
  55. $(".ui_radiobox[rel='"+rel+"']").removeClass("common_rdo_checked");
  56. $(".ui_radiobox[rel='"+rel+"']").find("input[type='radio']").attr("checked",false);
  57. o.attr("checked",checked);
  58. img.attr("checked",checked);
  59. img.addClass("common_rdo_checked");
  60. });
  61. }
  62. // 初始化复选框,该UI必为label,且内部需要有checkbox
  63. function ui_checkbox(){
  64. $(".ui_checkbox").each(function(){
  65. var img = $(this);
  66. var o = img.find("input[type='checkbox']");
  67. o.hide();
  68. var checked = $(o).attr("checked");
  69. img.addClass("common_cbo");
  70. img.attr("name",o.attr("name"));
  71. img.css({"display":"inline-block"});
  72. img.attr("checked",checked?true:false);
  73. if(checked){
  74. img.removeClass("common_cbo");
  75. img.removeClass("common_cbo_checked");
  76. img.addClass("common_cbo_checked");
  77. }
  78. else{
  79. img.removeClass("common_cbo");
  80. img.removeClass("common_cbo_checked");
  81. img.addClass("common_cbo");
  82. }
  83. });
  84. $(".ui_checkbox").hover(function(){
  85. var img = $(this);
  86. img.css("cursor","pointer");
  87. var o = img.find("input[type='checkbox']");
  88. var checked = o.attr("checked");
  89. if(!checked){
  90. $(this).addClass("common_cbo_hover");
  91. }
  92. },function(){
  93. $(this).removeClass("common_cbo_hover");
  94. });
  95. $(".ui_checkbox").find("input[type='checkbox']").bind("click",function(){
  96. return false;
  97. });
  98. $(".ui_checkbox").click(function(){
  99. var img = $(this);
  100. var o = img.find("input[type='checkbox']");
  101. var checked = $(o).attr("checked");
  102. var rel=img.attr("rel");
  103. $(".ui_checkbox[rel='"+rel+"']").removeClass("common_cbo_hover");
  104. checked = checked?false:true;
  105. o.attr("checked",checked);
  106. img.attr("checked",checked);
  107. if(checked){
  108. o.trigger("checkon");
  109. $(this).removeClass("common_cbo");
  110. $(this).addClass("common_cbo_checked");
  111. }
  112. else{
  113. o.trigger("checkoff");
  114. img.removeClass("common_cbo_checked");
  115. img.addClass("common_cbo");
  116. }
  117. });
  118. }
  119. // ui-button 鼠标悬浮替换颜色
  120. function button_hover(hoverObj){
  121. $(hoverObj).live('mouseover mouseout', function(){
  122. if($(this).hasClass("theme_bgcolor")){
  123. $(this).toggleClass("theme_bgcolor1");
  124. }
  125. if($(this).hasClass("bg_red")){
  126. $(this).toggleClass("bg_red1");
  127. }
  128. if($(this).hasClass("bg_gray")){
  129. $(this).toggleClass("bg_gray1");
  130. }
  131. if($(this).hasClass("bg_green")){
  132. $(this).toggleClass("bg_green1");
  133. }
  134. });
  135. }
  136. // 输入框提示文字显隐
  137. function show_tip(){
  138. var $textbox = $(".textbox , .small_textbox");
  139. $(".holder_tip").live('click',function(){
  140. $(this).hide();
  141. $(this).parent().find(".textbox , .small_textbox").focus();
  142. });
  143. $textbox.live('focus',function(){
  144. $(this).parent().find(".holder_tip").hide();
  145. });
  146. $textbox.live('blur',function(){
  147. if($(this).val()==""){
  148. $(this).parent().find(".holder_tip").show();
  149. }
  150. else{
  151. $(this).parent().find(".holder_tip").hide();
  152. }
  153. });
  154. $textbox.each(function(){
  155. if($(this).val()==""){
  156. $(this).parent().find(".holder_tip").show();
  157. }
  158. else{
  159. $(this).parent().find(".holder_tip").hide();
  160. }
  161. });
  162. }
  163. // 返回顶部
  164. function init_gotop(){
  165. $(window).scroll(function(){
  166. var s_top = $(document).scrollTop()+$(window).height()-70;
  167. if($.browser.msie && $.browser.version =="6.0"){
  168. $("#gotop").css("top",s_top);
  169. if($(document).scrollTop()>0){
  170. $("#gotop").css("visibility","visible");
  171. }
  172. else{
  173. $("#gotop").css("visibility","hidden");
  174. }
  175. }
  176. else{
  177. if($(document).scrollTop()>0){
  178. if($("#gotop").css("display")=="none")
  179. $("#gotop").fadeIn();
  180. }
  181. else{
  182. if($("#gotop").css("display")!="none")
  183. $("#gotop").fadeOut();
  184. }
  185. }
  186. });
  187. $("#gotop").bind("click",function(){
  188. $("html,body").animate({scrollTop:0},"fast","swing",function(){});
  189. });
  190. var top = $(document).scrollTop()+$(window).height()-70;
  191. if($.browser.msie && $.browser.version =="6.0"){
  192. $("#gotop").css("top",top);
  193. if($(document).scrollTop()>0){
  194. $("#gotop").css("visibility","visible");
  195. }
  196. else{
  197. $("#gotop").css("visibility","hidden");
  198. }
  199. }
  200. else{
  201. if($(document).scrollTop()>0){
  202. if($("#gotop").css("display")=="none")
  203. $("#gotop").show();
  204. }
  205. else{
  206. if($("#gotop").css("display")!="none")
  207. $("#gotop").hide();
  208. }
  209. }
  210. }