// JavaScript Document //图片左右切换 function DY_scroll(wraper,prev,next,img,speed,or) { var wraper = $(wraper); var prev = $(prev); var next = $(next); var img = $(img).find('ul'); var w = img.find('li').outerWidth(true); var s = speed; next.click(function() { img.animate({'margin-left':-w},function() { img.find('li').eq(0).appendTo(img); img.css({'margin-left':0}); }); }); prev.click(function() { img.find('li:last').prependTo(img); img.css({'margin-left':-w}); img.animate({'margin-left':0}); }); if (or == true) { ad = setInterval(function() { next.click();},s*1000); wraper.hover(function(){clearInterval(ad);},function(){ad = setInterval(function() { next.click();},s*1000);}); } } // DY_scroll('.img-scroll','.prev','.next','.img-list',3,true);// true为自动播放,不加此参数或false就默认不自动 //滚动 (function($){ $.fn.kxbdMarquee = function(options){ var opts = $.extend({},$.fn.kxbdMarquee.defaults, options); return this.each(function(){ var $marquee = $(this);//滚动元素容器 var _scrollObj = $marquee.get(0);//滚动元素容器DOM var scrollW = $marquee.width();//滚动元素容器的宽度 var scrollH = $marquee.height();//滚动元素容器的高度 var $element = $marquee.children(); //滚动元素 var $kids = $element.children();//滚动子元素 var scrollSize=0;//滚动元素尺寸 var _type = (opts.direction == 'left' || opts.direction == 'right') ? 1:0;//滚动类型,1左右,0上下 //防止滚动子元素比滚动元素宽而取不到实际滚动子元素宽度 //$element.css(_type?'width':'height',100000); //获取滚动元素的尺寸 if (opts.isEqual) { scrollSize = $kids[_type?'outerWidth':'outerHeight']() * $kids.length; }else{ $kids.each(function(){ scrollSize += $(this)[_type?'outerWidth':'outerHeight'](); }); } //滚动元素总尺寸小于容器尺寸,不滚动 if (scrollSize<(_type?scrollW:scrollH)) return; //克隆滚动子元素将其插入到滚动元素后,并设定滚动元素宽度 $element.append($kids.clone()).css(_type?'width':'height',scrollSize*2); var numMoved = 0; function scrollFunc(){ var _dir = (opts.direction == 'left' || opts.direction == 'right') ? 'scrollLeft':'scrollTop'; if (opts.loop > 0) { numMoved+=opts.scrollAmount; if(numMoved>scrollSize*opts.loop){ _scrollObj[_dir] = 0; return clearInterval(moveId); } } if(opts.direction == 'left' || opts.direction == 'up'){ var newPos = _scrollObj[_dir] + opts.scrollAmount; if(newPos>=scrollSize){ newPos -= scrollSize; } _scrollObj[_dir] = newPos; }else{ var newPos = _scrollObj[_dir] - opts.scrollAmount; if(newPos<=0){ newPos += scrollSize; } _scrollObj[_dir] = newPos; } }; //滚动开始 var moveId = setInterval(scrollFunc, opts.scrollDelay); //鼠标划过停止滚动 $marquee.hover( function(){ clearInterval(moveId); }, function(){ clearInterval(moveId); moveId = setInterval(scrollFunc, opts.scrollDelay); } ); //控制加速运动 if(opts.controlBtn){ $.each(opts.controlBtn, function(i,val){ $(val).bind(opts.eventA,function(){ opts.direction = i; opts.oldAmount = opts.scrollAmount; opts.scrollAmount = opts.newAmount; }).bind(opts.eventB,function(){ opts.scrollAmount = opts.oldAmount; }); }); } }); }; $.fn.kxbdMarquee.defaults = { isEqual:false,//所有滚动的元素长宽是否相等,true,false loop: 0,//循环滚动次数,0时无限 direction: 'up',//滚动方向,'left','right','up','down' scrollAmount:1,//步长 scrollDelay:60,//时长 newAmount:3,//加速滚动的步长 eventA:'mousedown',//鼠标事件,加速 eventB:'mouseup'//鼠标事件,原速 }; $.fn.kxbdMarquee.setDefaults = function(settings) { $.extend( $.fn.kxbdMarquee.defaults, settings ); }; })(jQuery); /*$(document).ready(function(){ $('.marquee').kxbdMarquee({ direction:'left', eventA:'mouseenter', eventB:'mouseleave' }); }); */ var i=0; function picChange(obj){ if(i<$(""+obj+" li").length-1){ i++; $(""+obj+" li").eq(i).fadeIn().siblings("li").fadeOut(); }else{ i=0; $(""+obj+" li").eq(i).fadeIn().siblings("li").fadeOut(); } } /*设为首页加入收藏*/ function AddFavorite(sURL, sTitle) { try { window.external.addFavorite(sURL, sTitle); } catch (e) { try { window.sidebar.addPanel(sTitle, sURL, ""); } catch (e) { alert("加入收藏失败,请使用Ctrl+D进行添加"); } } } function SetHome(obj,url){ try{ obj.style.behavior='url(#default#homepage)'; obj.setHomePage(url); } catch(e){ if(window.netscape) { try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch (e) { alert("此操作被浏览器拒绝!n请在浏览器地址栏输入‘about:config’并回车n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。"); } var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); prefs.setCharPref('browser.startup.homepage',url); } } } //文字上下滚动 function AutoScroll(obj){ $(obj).find("ul:first").animate({ marginTop:"-28px" },500,function(){ $(this).css({marginTop:"0px"}).find("li:first").appendTo(this); }); } //专题 function zhuantiMove(obj) { $(obj).addClass('current'); $(obj).siblings().removeClass('current'); var current = $("#zhuanti .icons li.current").index(); var zhuantiHeight = 189; $('#zhuanti .pics').animate({marginTop:-current * zhuantiHeight+'px'}); clearInterval(zhuantiInterval); window.zhuantiInterval = setInterval('zhuantiInit()',3000); } function zhuantiInit() { var current = $("#zhuanti .icons li.current").index(); var next = current + 1; if (next == $("#zhuanti .icons li").length) { next = 0; } var obj = $("#zhuanti .icons li").eq(next); zhuantiMove(obj); } //tab切换 function setTab(titleId,contentId,index) { var titleId="#"+titleId; var contentId="#"+contentId; if($(titleId).children("li").eq(index).attr("class")!="current"&&$(titleId).children("a").eq(index).attr("class")!="current"){ $(titleId).find(".morehref").attr("href",$(titleId).find(".current").attr("mylink")); $(titleId).children("a").each(function() { if ($(this).index()!=index) { //$(this)[0].className=""; $(this).removeClass("current"); } else { //$(this)[0].className="current"; $(this).addClass("current"); } }); $(""+titleId+" a").each(function() { if ($(this).index()!=index) { //$(this)[0].className=""; $(this).removeClass("current"); } else { //$(this)[0].className="current"; $(this).addClass("current"); } }); $(titleId).children("ul").children("li").each(function() { if ($(this).index()!=index) { //$(this)[0].className=""; $(this).removeClass("current"); } else { //$(this)[0].className="current"; $(this).addClass("current"); } }); $(contentId).children("ul").each(function() { if ($(this).index()!=index) { $(this)[0].style.display="none"; } else { $(this)[0].style.display="block"; } }); }; } //图片滚动 调用方法 imgscroll({speed: 30,amount: 1,dir: "up"}); $.fn.imgscroll = function(o){ var defaults = { speed: 40, amount: 0, width: 1, dir: "left" }; o = $.extend(defaults, o); return this.each(function(){ var _li = $("li", this); _li.parent().parent().css({overflow: "hidden", position: "relative"}); //div _li.parent().css({margin: "0", padding: "0", overflow: "hidden", position: "relative", "list-style": "none"}); //ul _li.css({position: "relative", overflow: "hidden"}); //li if(o.dir == "left") _li.css({float: "left"}); //初始大小 var _li_size = 0; for(var i=0; i<_li.size(); i++) _li_size += o.dir == "left" ? _li.eq(i).outerWidth(true) : _li.eq(i).outerHeight(true); //循环所需要的元素 if(o.dir == "left") _li.parent().css({width: (_li_size*3)+"px"}); _li.parent().empty().append(_li.clone()).append(_li.clone()).append(_li.clone()); _li = $("li", this); //滚动 var _li_scroll = 0; function goto(){ _li_scroll += o.width; if(_li_scroll > _li_size) { _li_scroll = 0; _li.parent().css(o.dir == "left" ? { left : -_li_scroll } : { top : -_li_scroll }); _li_scroll += o.width; } _li.parent().animate(o.dir == "left" ? { left : -_li_scroll } : { top : -_li_scroll }, o.amount); } //开始 var move = setInterval(function(){ goto(); }, o.speed); _li.parent().hover(function(){ clearInterval(move); },function(){ clearInterval(move); move = setInterval(function(){ goto(); }, o.speed); }); }); }; //$(document).ready(function(){ // $(".scrollleft").imgscroll({ // speed: 40, //图片滚动速度 // amount: 0, //图片滚动过渡时间 // width: 1, //图片滚动步数 /// dir: "left" // "left" 或 "up" 向左或向上滚动 // }); // $(".scrolltop").imgscroll({ // speed: 40, //图片滚动速度 // amount: 0, //图片滚动过渡时间 // width: 1, //图片滚动步数 // dir: "up" // "left" 或 "up" 向左或向上滚动 // }); //}); //select 模拟框 function selectBox(){ $(".options").hover(function(){ $(this).children("dd").show(); $(this).children("b").show(); }, function() { $(this).children("dd").hide(); }); $(".options ,.options div").hover(function(){ $(this).addClass("hover"); },function(){ $(this).removeClass("hover"); }); $(".options dd div").click(function(){ $("#text").val($(this).html());//当前 var s=$(this).attr("s"); window.open(s); $(this).children("dd").hide(); }); } //返回顶部 //滚动 $(window).scroll(function() { if($(this).scrollTop()>0){ $("#back-top").fadeIn(); }else{ $("#back-top").fadeOut(); } }) $(function(){ $("#back-top").click(function(){ $('body,html').animate({scrollTop:0},200); }) }) //导航当前 $(function(){ }) //图片放大 function showbigpic(obj) { window.w = $(obj).width(); window.h = $(obj).height(); window.oriX = $(obj).offset().left; window.oriY = $(obj).offset().top; var screenImage = $(obj); // Create new offscreen image to test var theImage = new Image(); theImage.src = screenImage.attr("src"); // Get accurate measurements from that. var imageWidth = theImage.width; var imageHeight = theImage.height; var targetH =imageHeight; var targetW =imageWidth; var targetX = ($(window).width() - targetW) / 2; var targetY = ($(window).height() - targetH) / 2 + $(document).scrollTop(); var html = ''; $("#alphabg").css({width:$(document).width()+"px",height:$(document).height()+"px"}); $("#alphabg").fadeIn(); $("body").append(html); $("#bigpic").animate({width:targetW+'px',height:targetH+'px',left:targetX+'px',top:targetY+'px'},1000,'swing',function() {$("#alphabg").css({width:$(document).width()+"px",height:$(document).height()+"px"});} ); } function remove_big() { $("#bigpic").animate({width:w+'px',height:h+'px',left:oriX+'px',top:oriY+'px'},1000,'swing',function() {$("#bigpic").remove();$("#alphabg").fadeOut();}); } //单行新闻 function AutoScroll(obj){ $(obj).find("ul:first").animate({ marginTop:"-40px" },1000,function(){ $(this).css({marginTop:"0px"}).find("a:first").appendTo(this); }); } //超出显示省略号 jQuery.fn.limit=function(){ var self = $("[limit]"); self.each(function(){ var objString = $(this).text(); var objLength = $(this).text().length; var num = $(this).attr("limit"); if(objLength > num){ $(this).attr("title",objString); objString = $(this).text(objString.substring(0,num) + "..."); } }) }