/** * @l_slide the effect 0f web * @version 1.0 * @author 徐海洁 **/ //新闻上下滚动效果//id1不可绝对定位,否则无法滚动 /.news_nr (function () { var haiscrolltop = function(id1,timer,fudu){ var $parent = $("."+id1); $parent.wrap("
"); $parent.clone().appendto($(".news_right_kh")); var areap = $parent.css("padding"); var areabg = $parent.css("background"); $(".news_right_kh>div").css({padding:0}); var areaw = $parent.outerwidth(); var areah = $parent.outerheight(); $(".news_right_area").css({overflow:"hidden",height:areah,width:areaw,padding:areap,background:areabg}); $(".news_right_area1").css({overflow:"hidden",height:areah,width:areaw}); var i = 0; function wavescroll() { if (i < $parent.outerheight()) { i = i + fudu; $(".news_right_area1").scrolltop(i); //$(".news_right_area1").animate({scrolltop:i},1000);图片向上滚动 } else { i = 0; $(".news_right_area1").scrolltop(i); //$(".news_right_area1").animate({scrolltop:i},1000);图片向上滚动 } } var auto = setinterval(wavescroll, timer); $(".news_right_area1").hover(function() { clearinterval(auto) },function(){ auto = setinterval(wavescroll, timer); }) } window.haiscrolltop = haiscrolltop; })(); //左右滚动效果带左右按钮//滚动的ul,左右按钮和时间间距 (function () { var hairightscroll = function(class1,class2,class3,timer){ var $parent = $("."+class1); var $btnleft = $("."+class2); var $btnright = $("."+class3); var divoutwidth = $parent.children().outerwidth(true); $parent.css({width:"9999px",position:"relative",marginleft:-divoutwidth+"px"}); function scrollleft(){ $parent.animate({marginleft:-divoutwidth*2+"px"},function(){ $parent.children().first().appendto($parent); $(this).css({marginleft:-divoutwidth+"px"}); }) } var auto1 = setinterval(scrollleft, timer); $parent.parent().hover(function() { clearinterval(auto1) },function(){ auto1 = setinterval(scrollleft, timer); }) var time = new date(); $btnleft.click(function(){ if(new date()-time>500){ time = new date(); $parent.animate({marginleft:0},function(){ $parent.children().last().prependto($parent); $(this).css({marginleft:-divoutwidth+"px"}); }) } }) $btnright.click(function(){ if(new date()-time>500){ time = new date(); scrollleft(); } }) } window.hairightscroll = hairightscroll; })(); //上下滚动效果带左右按钮//滚动的ul,左右按钮和时间间距 (function () { var haitopscroll = function(class1,class2,class3,timer){ var $parent = $("."+class1); var $btnleft = $("."+class2); var $btnright = $("."+class3); var divoutheight = $parent.children().outerheight(true); $parent.css({height:"9998px",position:"relative",margintop:-divoutheight+"px"}); function scrollleft(){ $parent.animate({margintop:-divoutheight*2+"px"},function(){ $parent.children().first().appendto($parent); $(this).css({margintop:-divoutheight+"px"}); }) } var auto1 = setinterval(scrollleft, timer); $parent.parent().hover(function() { clearinterval(auto1) },function(){ auto1 = setinterval(scrollleft, timer); }) var time = new date(); $btnleft.click(function(){ if(new date()-time>500){ time = new date(); $parent.animate({margintop:0},function(){ $parent.children().last().prependto($parent); $(this).css({margintop:-divoutheight+"px"}); }) } }) $btnright.click(function(){ if(new date()-time>500){ time = new date(); scrollleft(); } }) } window.haitopscroll = haitopscroll; })(); //根据网址末尾,当前tab加载悬浮效果。/悬浮的li class1 /悬浮效果class2 (function () { var haiwebtab = function(class1,class2){ var $parent = $("."+class1); var url = location.href; var www = url.split("/"); $parent.each(function(){ var aurl = $(this).find("a").attr("href"); var awww = aurl.split("/"); var www1 = www[www.length-1];//获取当前网址域名的最后一个字符串。 var awww1 = awww[awww.length-1];//获取a标签的最后一个字符串。 if(www1==awww1){ $(this).addclass(class2); } }); } window.haiwebtab = haiwebtab; })(); //数字滚动效果滚动的class/滚动幅度/时间间距(越小越流畅) (function () { var haiscrollnum = function(class1,fudu,timer){ var $parent = $("."+class1); var endnum = parseint($parent.text()); var beginnum = 0; var play =null; var flag = 0; $(window).scroll(function(){ var screenh = $(window).height();//屏幕高度 var postertop = $parent.offset().top;//元素距离顶部的高度 var gao = $(window).scrolltop();//滚动条高度 if(flag == 0){ if(gao + screenh > postertop +200){ auto(); flag = 1; } } }) function auto(){ play = setinterval(function(){ if(beginnum$parent.offset().top){ $parent.addclass(class2) } }) } window.haichufa = haichufa; })(); /** * 显示隐藏的tab效果带定时器 */ (function () { var haitab = function(li,section,cur,on,time){ var $li = $("."+li); var $section = $("."+section); var lilenght = $li.length; var num = 0; var play = null; var $time = time|5000; $section.eq(0).addclass(on); $li.eq(0).addclass(cur); function cha(num) { $li.eq(num).addclass(cur).siblings().removeclass(cur); $section.eq(num).addclass(on).siblings().removeclass(on); } auto(num); function auto(num) { play = setinterval(function () { num++; num=num>lilenght-1?0:num; cha(num); },$time) } $li.click(function () { clearinterval(play); var num = $(this).index(); console.log(num) cha(num); auto(num) }) } window.haitab = haitab; })(); /** * 手风气推拉门效果+定时器 */ (function () { var haishoufengqin = function(li,section,time){ var $li = $("."+li); var $section = $("."+section); var $time =time|5000; var play = null; var index= 0; var len = $li.length; var liw1 =$li.width(); var liw2 = $section.width(); $li.eq(0).stop().animate({width:liw2+"px"}); auto(index); function biankuan(index) { $li.eq(index).stop().animate({width:liw2+"px"}).siblings().stop().animate({width:liw1+"px"}); } function auto(index) { play = setinterval(function () { index++; index%=len; biankuan(index); },$time) } $li.hover(function () { clearinterval(play); },function () { auto(index) }) $li.each(function () { $(this).click(function () { index = $(this).index(); biankuan(index); }) }) } window.haishoufengqin = haishoufengqin; })(); /** * 图片自适应撑满外框 */ (function () { var haipicwh = function(div,img){ var $div = $("."+div); var $img = $("."+img); $img.each(function () { if($div.width()/$div.height()>$(this).width()/$(this).height()){ var divw =$div.width();//获取盒子宽度 var imgh =$(this).height()*$div.width()/$(this).width(); var heightcha =(imgh-$div.height())/2; $(this).css({width:divw,height:imgh,margintop:-heightcha}) }else{ var divh =$div.height(); var imgw =$(this).width()*$div.height()/$(this).height(); var widthcha =(imgw-$div.width())/2; $(this).css({width:imgw,height:divh,marginleft:-widthcha}) } }) } window.haipicwh = haipicwh; })(); //事件滚动触发 class1 目标 class2 触发效果 timer延迟事件 (function () { var haichufa = function(class1,class2,timer){ var timer = timer || 0; var $parent = $("."+class1); $(window).scroll(function(){ if($(document).scrolltop()+$(window).height()>$parent.offset().top){ settimeout(function(){ $parent.addclass(class2) },timer) } }) } window.haichufa = haichufa; })();