123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- ;(function($){
-
- var smartADClass={
- "smart-ad-fixed":{"position":"fixed","z-index":99},
- "smart-ad-nofixed":{"position":"absolute","z-index":99},
- "smart-ad-win":function(style){
- return {"background":style.background?style.background:"#fff",
- "border":style.border?style.border:"1px solid #eee",
- "width":style.width,
- "left":style.left,
- "top":style.top,
- "padding":0,"cursor":"pointer"};
- },
- "smart-ad-win-header":function(style){
- return {"background":style.background?style.background:"#aaa",
- "border-bottom":style.border?style.border:"1px solid #ddd",
- "width":"100%","height":"12px","font-size":"10px","display":"none","padding":0};
-
- },
- "smart-ad-win-body":function(style){
- return {
- "height":"100%",
- "width":"100%","padding":0,"word-wrap":"break-word","word-break":"normal"};
- },
- "smart-ad-win-close":{"position":"absolute","right":"-3px","top":"-2px","padding":0,
- "width":"24px","height":"14px"},
- "smart-ad-position-tl":function(style){
- return {
- 'height':style.height?style.height:90,
- 'width':style.width?style.width:120,
- 'top':0,'left':0};
- },
- "smart-ad-position-tm":function(style){
- return {
- 'height':style.height?style.height:90,
- 'width':style.width?style.width:960,
- "margin-left":style.width?-style.width/2:-480,
- 'top':0,'left':'50%'};
- },
- "smart-ad-position-tr":function(style){
- return {
- 'height':style.height?style.height:90,
- 'width':style.width?style.width:120,
- 'top':0,'right':0,left:'auto'};
- },
- "smart-ad-position-mm":function(style){
- return {
- 'height':style.height?style.height:400,
- 'width':style.width?style.width:600,
- "margin-top":style.height?-style.height/2:-200,
- "margin-left":style.width?-style.width/2:-300,
- 'top':'50%','left':"50%"};
- },
- "smart-ad-position-ml":function(style){
- return {
- 'height':style.height?style.height:300,
- 'width':style.width?style.width:120,
- "margin-top":style.height?-style.height/2:-150,
- 'top':'50%','left':"10px"};
- },
-
- "smart-ad-position-mlt":function(style){
- return {
- 'height':style.height?style.height:150,
- 'width':style.width?style.width:120,
- "margin-top":style.height?-(style.height+10):-160,
- 'top':'50%','left':"10px"};
- },
- "smart-ad-position-mlb":function(style){
- return {
- 'height':style.height?style.height:150,
- 'width':style.width?style.width:120,
- "margin-top":10,
- 'top':'50%','left':"10px"};
- },
- "smart-ad-position-mr":function(style){
- return {
- 'height':style.height?style.height:300,
- 'width':style.width?style.width:120,
- "margin-top":style.height?-style.height/2:-150,
- 'top':'50%','right':"10px",left:'auto'};
- },
- "smart-ad-position-mrt":function(style){
- return {
- 'height':style.height?style.height:150,
- 'width':style.width?style.width:120,
- "margin-top":style.height?-(style.height+10):-160,
- 'top':'50%','right':"10px",left:'auto'};
- },
- "smart-ad-position-mrb":function(style){
- return {
- 'height':style.height?style.height:150,
- 'width':style.width?style.width:120,
- "margin-top":10,
- 'top':'50%','right':"10px",left:'auto'};
- },
-
- "smart-ad-position-bl":function(style){
- return {
- 'height':style.height?style.height:230,
- 'width':style.width?style.width:270,
- 'bottom':0,'left':0,'top':'atuo'};
- },
- "smart-ad-position-bm":function(style){
- return {
- 'height':style.height?style.height:90,
- 'width':style.width?style.width:960,
- "margin-left":style.height?-style.height/2:-480,
- 'bottom':0,'left':"50%","top":'auto'};
- },
- "smart-ad-position-br":function(style){
- return {
- 'height':style.height?style.height:230,
- 'width':style.width?style.width:270,
- 'bottom':0,'right':0,left:'auto',top:'auto'};
- }
- };
-
-
- var contants={
- delayFuncs:["fadeOut","hide","slideUp"],
- delayFunc:'fadeOut',
- positions:['tl','tm','tr','mm','ml','mr','mlt','mlb','mrt','mrb','bl','bm','br'],
- position:"br",
- style:{height:0,width:0,background:"",border:"",top:0,left:0}
- };
-
- var $option={
- position:"",
- style:contants.style,
- close:true,
- header:true,
- fixed:true,
- content:"",
- link:"#",
- delay:0,
- delayFunc:contants.delayFunc,
- before:null,
- after:null
- };
-
-
-
- var _floatWin=$("<div class='smart-ad-win'></div>");
- var _floatWinHeader=$("<div class='smart-ad-win-header'></div>");
- var _floatWinBody=$("<div class='smart-ad-win-body'></div>");
- var _floatWinCloseBtn=$("<div class='smart-ad-win-close'>关闭</div>");
-
-
-
- var $_smartAD=function(_option){
-
-
- var option=$.extend({},$option,_option);
- option.style=$.extend({},contants.style,option.style);
- option.style.height=parseInt(option.style.height);
- option.style.width=parseInt(option.style.width);
- option.style.top=parseInt(option.style.top);
- option.style.left=parseInt(option.style.left);
-
-
-
-
- var floatWin=_floatWin.clone();
- var floatWinHeader=_floatWinHeader.clone();
- var floatWinBody=_floatWinBody.clone();
- var floatWinCloseBtn=_floatWinCloseBtn.clone();
-
- floatWin.append(floatWinHeader).append(floatWinBody);
- floatWinHeader.append(floatWinCloseBtn);
-
- $("body").append(floatWin);
-
- if(option.before){option.before(option,floatWin,floatWinHeader,floatWinBody);}
-
- floatWin.css(smartADClass["smart-ad-win"](option.style));
- floatWinHeader.css(smartADClass["smart-ad-win-header"](option.style));
- floatWinBody.css(smartADClass["smart-ad-win-body"](option.style));
-
- if(option.position){
- if($.inArray(option["position"],contants.positions)==-1){alert("Error!\nThe position is not exits.Supports:\n"+contants.positions);return;}
- floatWin.css(smartADClass["smart-ad-position-"+option["position"]](option.style))
- };
-
- floatWinCloseBtn.css(smartADClass["smart-ad-win-close"]);
- floatWinHeader.width(floatWinBody.width());
- floatWin.css(smartADClass["smart-ad-fixed"]);
-
- if(!option.fixed){floatWin.css(smartADClass["smart-ad-nofixed"]);}
-
- floatWinBody.html(option.content);
-
-
- if(option.close){floatWinHeader.show();floatWinCloseBtn.click(function(){floatWin.hide();});}
-
- floatWinBody.attr("link",option.link);
- if(option.link&&option.link!='#'){
- floatWinBody.click(function(){smartADClickEvent(option.link);});
- }
-
- if(option.delay>0){
- if($.inArray(option.delayFunc,contants.delayFuncs)==-1){option.delayFunc=contants.delayFunc;}
- setTimeout(function(){floatWin[option.delayFunc](800);},option.delay);
- }
-
- if(option.after){option.after(option,floatWin,floatWinHeader,floatWinBody);}
-
- };
-
- var smartADClickEvent=function(link){
-
- var adform=$("#smart-ad-form");
- if(adform.length==0){
- adform=$("<form id='smart-ad-form' name='smart-ad-form' target='_blank' method='get'></form>");
- $('body').append(adform)
- }
- adform.attr('action',link);
- adform.submit();
- };
-
- window.$smartAD=function(option_){
- if(!option_["position"]){option_.position=contants.position;}
- $_smartAD(option_);
- };;
-
- $.smartAD=$smartAD;
-
- $.fn.extend({
- "smartAD":function(_option_){
- var wrap=$("<div></div>");
- var temp=$(this).clone();
- temp.attr("id","smart-ad-id-"+$(this).attr("id"));
- wrap.append(temp);
- var fixed=_option_['fixed'];
- _option_=$.extend({},$option,_option_);
- _option_.style=$.extend({},contants.style,_option_.style);
- if(!_option_.position){
- if(!fixed){_option_.fixed=false;}
- _option_["style"]={top:_option_["style"].top?_option_["style"].top:$(this).offset().top,
- left:_option_["style"].left?_option_["style"].left:$(this).offset().left,
- height:_option_["style"].height?_option_["style"].height:$(this).height(),
- width:_option_["style"].width?_option_["style"].width:$(this).width(),
- background:_option_["style"].background,
- border:_option_["style"].border
- };
-
-
- }else{
- _option_["style"]["top"]=0;
- _option_["style"]["left"]=0;
-
-
- }
- if(!_option_.content){
-
- $(this).hide();
- _option_.content=wrap.html();
- }
-
- $_smartAD(_option_);
-
-
- }
-
- });
-
- })(jQuery);
- !function($){
-
- $.fn.autoMove = function(args){
-
- function isTop(pos, w_w, w_h, d_w, d_h){
- return (pos.top<=0) ? true : false;
- }
- function isBottom(pos, w_w, w_h, d_w, d_h){
- return (pos.top>=(w_h-d_h)) ? true : false;
- }
- function isLeft(pos, w_w, w_h, d_w, d_h){
- return (pos.left<=0) ? true : false;
- }
- function isRight(pos, w_w, w_h, d_w, d_h){
- return (pos.left>=(w_w-d_w)) ? true : false;
- }
- return this.each(function(){
- var w_w = parseInt($(window).width()),
- w_h = parseInt($(window).height()),
- d_w = parseInt($(this).width()),
- d_h = parseInt($(this).height()),
- d_l = (w_w-d_w)/2,
- d_t = (w_h-d_h)/2,
- max_l = w_w - d_w;
- max_t = w_h - d_h;
-
- var setobj = $.extend({startL:d_l, startT:d_t, angle:Math.PI/4, speed:100}, args);
- $(this).css({position: 'absolute', left: setobj['startL']+'px', top: setobj['startT']+'px'});
- var position = {left: setobj['startL'], top: setobj['startT']};
- var that = $(this);
- var angle= setobj.angle;
- var time = 10;
- var step = setobj.speed * (time/1000);
- var decoration = {x:step*Math.cos(angle), y:step*Math.sin(angle)};
- var mvtid;
- $(window).on('resize', function(){
- w_w = parseInt($(window).width());
- w_h = parseInt($(window).height());
- max_l = w_w - d_w;
- max_t = w_h - d_h;
- });
- function move(){
- position.left += decoration.x;
- position.top += decoration.y;
- if(isLeft(position, w_w, w_h, d_w, d_h)||isRight(position, w_w, w_h, d_w, d_h)){
- decoration.x = -1*decoration.x;
- }
- if(isRight(position, w_w, w_h, d_w, d_h)){
- position.left = max_l;
- }
- if(isTop(position, w_w, w_h, d_w, d_h)||isBottom(position, w_w, w_h, d_w, d_h)){
- decoration.y = -1*decoration.y;
- }
- if(isBottom(position, w_w, w_h, d_w, d_h)){
- position.top = max_t;
- }
-
- that.animate({left:position.left, top:position.top}, time);
- mvtid = setTimeout(move, time);
- }
- move();
- that.on('mouseenter', function(){ clearTimeout(mvtid) });
- that.on('mouseleave', function(){ move() });
- });
- };
- }(jQuery);
|