bocfe.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // 默认obj为执行元素
  2. // HOVER
  3. // 默认样式 .h , 默认Hover样式 .hover
  4. // 自定义HOVER可使用 Hover(obj, classname)
  5. $(function(){
  6. $(".h").hover(function(){
  7. $(this).addClass("hover")
  8. }, function(){
  9. $(this).removeClass("hover")
  10. })
  11. })
  12. function Hover(obj, classname) {
  13. obj.hover(function(){
  14. $(this).addClass(classname)
  15. }, function(){
  16. $(this).removeClass(classname)
  17. })
  18. }
  19. // TAB
  20. // 默认焦点样式 .cur
  21. // 为防止xp系统opacity可能出现的锯齿或边缘模糊, 默认.tabbox效果.show() / .hide()
  22. // 拓展.tabbox成opacity, 需在.tabbox上加上 data-effect="true"
  23. function Tab(tabBtn, tabBox) {
  24. var tabbl = true;
  25. tabBtn.eq(0).addClass("cur")
  26. tabBox.eq(0).show()
  27. tabBtn.click(function(){
  28. var n = $(this).index();
  29. $(this).addClass("cur").siblings().removeClass("cur")
  30. if(tabBox.attr("data-effect") == "true"){
  31. if(!tabbl){
  32. return
  33. }
  34. tabbl = false;
  35. tabBox.eq(n).stop().fadeIn(800).siblings().stop().fadeOut(800, function(){
  36. tabbl = true;
  37. })
  38. }else{
  39. tabBox.eq(n).show().siblings().hide()
  40. }
  41. })
  42. }
  43. // 图片全屏 / 图片充满整个父级
  44. // 默认box自带loading背景图
  45. // 默认obj hide
  46. function FullBg(box, obj){
  47. box.css("background", "none")
  48. obj.eq(0).stop().fadeIn(1000)
  49. function resizeBg() {
  50. obj.removeClass("w-f").removeClass("h-f").css("margin", 0)
  51. var boxR = box.outerWidth() / box.outerHeight(),
  52. objR = obj.width() / obj.height();
  53. if( objR < boxR ) {
  54. obj.addClass('w-f').css("margin-top", -(obj.height() - box.outerHeight()) / 2);
  55. }else{
  56. obj.addClass('h-f').css("margin-left", -(obj.width() - box.outerWidth()) / 2);
  57. }
  58. }
  59. $(window).resize(resizeBg).trigger("resize");
  60. }
  61. // 视频全屏 / 视频充满整个父级 (video获取宽高有问题)
  62. function videoFull(obj, width, height){
  63. var $video = obj
  64. function resizeBg() {
  65. $video.attr("width", "").attr("height", "").attr("style", "")
  66. var boxR = $('.top-video').outerWidth() / $('.top-video').outerHeight(),
  67. objR = width / height;
  68. if( objR < boxR ) {
  69. $video.attr("width", "100%")
  70. var videoHeight = $video.width() / objR
  71. var top = - (videoHeight - $('.top-video').outerHeight()) / 2 > 0 ? 0 : - (videoHeight - $('.top-video').outerHeight()) / 2
  72. $video.css("margin-top", top);
  73. }else{
  74. $video.attr("height", "100%")
  75. var videoWidth = $video.height() * objR
  76. var left = - (videoWidth - $('.top-video').outerWidth()) / 2 > 0 ? 0 : - (videoWidth - $('.top-video').outerWidth()) / 2
  77. $video.css("margin-left", left);
  78. }
  79. }
  80. $(window).resize(resizeBg).trigger("resize");
  81. }
  82. // 标签进场效果
  83. // 用于多平级标签依次载入 默认标签具有position属性及opacuty: 0;
  84. // direction 从哪个方向进入
  85. // distance 进入到指定距离
  86. // number 平级标签的个数
  87. // time 进场动画的时间
  88. // delay 下一标签的延迟
  89. // callback 回调函数
  90. function Enter(obj, direction, distance, number, time, delay, callback) {
  91. // 从左往右,distance > 0
  92. if(direction == "left"){
  93. obj.stop().animate({
  94. left : distance,
  95. opacity : 1
  96. }, time)
  97. setTimeout(function(){
  98. if(obj.next().index() != -1){
  99. Enter(obj.next(), direction, distance, number, time, delay, callback)
  100. }else{
  101. setTimeout(function(){
  102. callback = callback || function(){};
  103. callback ();
  104. return
  105. }, time - delay)
  106. }
  107. }, delay)
  108. }
  109. // 从上往下,distance > 0
  110. if(direction == "top"){
  111. obj.stop().animate({
  112. top : distance,
  113. opacity : 1
  114. }, time)
  115. setTimeout(function(){
  116. if(obj.next().index() != -1){
  117. Enter(obj.next(), direction, distance, number, time, delay, callback)
  118. }else{
  119. setTimeout(function(){
  120. callback = callback || function(){};
  121. callback ();
  122. return
  123. }, time - delay)
  124. }
  125. }, delay)
  126. }
  127. // CSS3 X位移
  128. if(direction == "X"){
  129. obj.stop().transition({
  130. x : distance,
  131. opacity : 1
  132. }, time)
  133. setTimeout(function(){
  134. if(obj.next().index() != -1){
  135. Enter(obj.next(), direction, distance, number, time, delay, callback)
  136. }else{
  137. setTimeout(function(){
  138. callback = callback || function(){};
  139. callback ();
  140. return
  141. }, time - delay)
  142. }
  143. }, delay)
  144. }
  145. // CSS3 y位移
  146. if(direction == "Y"){
  147. obj.stop().transition({
  148. y : distance,
  149. opacity : 1
  150. }, time)
  151. setTimeout(function(){
  152. if(obj.next().index() != -1){
  153. Enter(obj.next(), direction, distance, number, time, delay, callback)
  154. }else{
  155. setTimeout(function(){
  156. callback = callback || function(){};
  157. callback ();
  158. return
  159. }, time - delay)
  160. }
  161. }, delay)
  162. }
  163. }
  164. // 图片加载 调用方法
  165. // _PreLoadImg([
  166. // 图片路径(数组形式)
  167. // ],function(){
  168. // })
  169. function _PreLoadImg(b,e){var c=0,a={},d=0;for(src in b){d++}for(src in b){a[src]=new Image();a[src].onload=function(){if(++c>=d){e(a)}};a[src].src=b[src]}};