jquery:关于$().css("left","")的设置;offset();offset().left();$.width();$.outerWidth();

1、css("left","")

问题:$().css("left",fLeft) 弹出取值为auto,无法设置。

改为:$("#lPhoto").css("left", fLeft).fadeIn(500);   left起作用。


问题:$("img").width()   必须在<img>标签中先写了width的值才能取到。


问题: $(".imgsize:eq(i)"  循环的写法  $(".imgsize:eq(" + i + ")"  //都是双引号。


问题:设置不了图片的地址

错误:     $("#lPhoto").find("img").attr("src", "images/photo/" + toSrc-1 + ".jpg");

正确:toSrc = toSrc - 1;   // toSrcn =parseInt(toSrcn)+1;

           $("#lPhoto").find("img").attr("src", "images/photo/" + toSrc + ".jpg");


2、$().offset()

返回或设置匹配元素相对于文档的偏移位置。

两个属性:top,left

不同表示方法:

(1) $().offset().top, $().offset().left

(2) $().offset({top:100,left:100});

(3) $().offset(function(n,c){        

// n默认为选择器当前index位置,可选;c默认为选择器当前坐标,可选。即:此处写上c就是当前坐标,不用从外部写。

      var newpos = new Object();

       newpos.left = c.left+100;

       newpos.top = c.top+100;

       return newpos;              // 返回新坐标

});

(4) $().offset(x.offset());


3、$.width();$.height();$.innerWidth();$.innerHeight();$.outerWidth();$.outerHeight()

eg:<div style="width:100px;height:100px;padding:10px 25px;border:1px solid #000"></div>

$.width()  // 返回元素的宽度,不包括内边距、边框和外边距:100px

$.height() // 设置或返回元素的高度  ,不包括内边距、边框和外边距:100px

$.innerWidth() // 包括元素的宽度和内边距:150px

$.innerHeight() // 包括元素的高度和内边距:120px

$.outerWidth() // 包括元素的宽度、边框和内边距:152px

$.outerHeight() // 包括元素的高度、边框和内边距:122px


获取元素本身到定位元素的距离:$.offset().top+($.outerWidth()-$.width())/2







  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
/* * JQZoom Evolution 1.0.1 - Javascript Image magnifier * * Copyright (c) Engineer Renzi Marco(www.mind-projects.it) * * $Date: 12-12-2008 * * ChangeLog: * * $License : GPL,so any change to the code you should copy and paste this section,and would be nice to report this to me([email protected]). */ (function($) { $.fn.jqzoom = function(options) { var settings = { zoomType: 'standard', //standard/reverse/innerzoom zoomWidth: 400, //zoomed width default width zoomHeight: 400, //zoomed div default width xOffset: 10, //zoomed div default offset yOffset: 0, position: "right" ,//zoomed div default position,offset position is to the right of the image lens:true, //zooming lens over the image,by default is 1; lensReset : false, imageOpacity: 0.2, title : true, alwaysOn: false, showEffect: 'show', hideEffect: 'hide', fadeinSpeed: 'fast', fadeoutSpeed: 'slow', preloadImages :true, showPreload: true, preloadText : 'Loading zoom', preloadPosition : 'center' //bycss }; //extending options options = options || {}; $.extend(settings, options); return this.each(function() { var a = $(this); var aTitle = a.attr('title'); //variabile per memorizzare il titolo href $(a).removeAttr('title'); $(a).css('outline-style','none'); var img = $("img", this); var imageTitle = img.attr('title'); img.removeAttr('title'); //variabile per memorizzare il titolo immagine var smallimage = new Smallimage( img ); var smallimagedata = {}; //imageborder var btop = 0; var bleft = 0; var loader = null; //variabile per memorizzare oggetto loader loader = new Loader(); var ZoomTitle = (trim(aTitle).length > 0) ? aTitle : (trim(imageTitle).length > 0) ? imageTitle : null; //setting zoomtitle var ZoomTitleObj = new zoomTitle(); var largeimage = new Largeimage( a[0].href ); var lens = new Lens(); var lensdata = {}; //lensborder var largeimageloaded = false; var scale = {}; //rapporto tra immagine grande e piccola scale.x/scale.y var stage = null; // quadrato che mostra l'immagine ingrandita var running = false; // running = true quando si verifica l'evento che mostra lo zoom(adesso mouseover). var mousepos = {}; var firstime = 0; var preloadshow = false; var isMouseDown = false; var dragstatus = false //loading smallimagedata smallimage.loadimage(); //ritorna false al click dell href $(this).click(function(){return false;}); //se settato alwaysOn attivo lo Zoom e lo mostro. //attivo al mouseover $(this).hover(function(e) { mousepos.x = e.pageX; mousepos.y = e.pageY; activate(); },function() { deactivate(); }); //ALWAYS ON if(settings.alwaysOn) { setTimeout(function(){activate();},150); } function activate() { if ( !running ) { //finding border smallimage.findborder(); running = true; //rimuovo il titolo al mouseover imageTitle = img.attr('title'); img.removeAttr('title'); aTitle = a.attr('title'); $(a).removeAttr('title'); //se non c?creo l'oggetto largeimage if (!largeimage || $.browser.safari) { largeimage = new Largeimage( a[0].href ); } //se l'immagine grande non ?stata caricata la carico if(!largeimageloaded || $.browser.safari) { largeimage.loadimage(); }else { //after preload if(settings.zoomType != 'innerzoom') { stage = new Stage(); stage.activate(); } lens = new Lens; lens.activate(); } //hack per MAC /* if($.browser.safari) { if(settings.zoomType != 'innerzoom') //se innerzoom non mostro la finestra dello zoom { stage = new Stage(); stage.activate(); } if($('div.jqZoomPup').length <= 0) { lens = new Lens(); } //if(settings.zoomType == 'innerzoom'){lens = new Lens()}; lens.activate(); (settings.alwaysOn) ? lens.center() : lens.setposition(null); } */ a[0].blur(); //alert($('div.jqZoomPup').length); return false; } } function deactivate() { if(settings.zoomType == 'reverse' && !settings.alwaysOn) { img.css({'opacity' : 1}); } if(!settings.alwaysOn) { //resetting parameters running = false; largeimageloaded = false; $(lens.node).unbind('mousemove'); lens.remove(); if($('div.jqZoomWindow').length >0) { stage.remove(); } if($('div.jqZoomTitle').length > 0) { ZoomTitleObj.remove(); } //resetting title img.attr('title',imageTitle); a.attr('title',aTitle); $().unbind(); a.unbind('mousemove'); //resetto il parametro che mi dice che ?la prima volta che mostor lo zoom firstime = 0; //remove ieiframe if(jQuery('.zoom_ieframe').length > 0) { jQuery('.zoom_ieframe').remove(); } }else { if(settings.lensReset) { switch(settings.zoomType) { case 'innerzoom': largeimage.setcenter(); break; default: lens.center(); break; } } } //non so se serve da provare if(settings.alwaysOn) { activate(); } }; //smallimage function Smallimage( image ) { this.node = image[0]; this.loadimage = function() { this.node.src = image[0].src; }; this.findborder = function() { var bordertop = ''; bordertop = $(img).css('border-top-width'); btop = ''; var borderleft = ''; borderleft = $(img).css('border-left-width'); bleft = ''; /*if($.browser.msie) { var temp = bordertop.split(' '); bordertop = temp[1]; var temp = borderleft.split(' '); borderleft = temp[1]; }*/ if(bordertop) { for(i=0;i<3;i++) { var x = []; x = bordertop.substr(i,1); if(isNaN(x) == false) { btop = btop +''+ bordertop.substr(i,1); }else { break; } } } if(borderleft) { for(i=0;i<3;i++) { if(!isNaN(borderleft.substr(i,1))) { bleft = bleft + borderleft.substr(i,1) }else { break; } } } btop = (btop.length > 0) ? eval(btop) : 0; bleft = (bleft.length > 0) ? eval(bleft) : 0; } this.node.onload = function() { //setto il cursor e la posizione dell'href a.css({'cursor':'crosshair','display':'block'}); if(a.css('position')!= 'absolute' && a.parent().css('position')) { a.css({'cursor':'crosshair','position':'relative','display':'block'}); } if(a.parent().css('position') != 'absolute') { a.parent().css('position','relative'); //a.css('position','relative'); } else{ //a.css('position','relative'); } if($.browser.safari || $.browser.opera) { $(img).css({position:'absolute',top:'0px',left:'0px'}); } /*if(a.css('position')!= 'absolute' && a.parent().css('position')) { a.css({'cursor':'crosshair','position':'relative','display':'block'}); } if(a.parent().css('position') != 'absolute') { alert('in'); a.parent().css('position','relative'); //a.css('position','relative'); } else{ //a.css('position','relative'); }*/ /* if(a.parent().css('position') != 'relative' && a.css('position') != 'absolute') { a.css({'cursor':'crosshair','position':'relative','display':'block'}); }*/ //al docuemnt ready viene caricato l'src quindi viene azionato l'onload e carico tutti i dati smallimagedata.w = $( this ).width(); smallimagedata.h = $( this ).height(); //non viene fatta assegnazione alla variabile globale smallimagedata.h = $( this ).height(); smallimagedata.pos = $( this ).offset(); smallimagedata.pos.l = $( this ).offset().left; smallimagedata.pos.t = $( this ).offset().top; smallimagedata.pos.r = smallimagedata.w + smallimagedata.pos.l; smallimagedata.pos.b = smallimagedata.h + smallimagedata.pos.t; //per sicurezza setto l'altezza e la width dell'href a.height(smallimagedata.h); a.width(smallimagedata.w); //PRELOAD IMAGES if(settings.preloadImages) { largeimage.loadimage(); } }; return this; }; //Lens function Lens() { //creating element and adding class this.node = document.createElement("div"); $(this.node).addClass('jqZoomPup'); this.node.onerror = function() { $( lens.node ).remove(); lens = new Lens(); lens.activate() ; }; //funzione privata per il caricamento dello zoom this.loadlens = function() { switch(settings.zoomType) { case 'reverse': this.image = new Image(); this.image.src = smallimage.node.src; // fires off async this.node.appendChild( this.image ); $( this.node ).css({'opacity' : 1}); break; case 'innerzoom': this.image = new Image(); this.image.src = largeimage.node.src; // fires off async this.node.appendChild( this.image ); $( this.node ).css({'opacity' : 1}); break default: break; } switch(settings.zoomType) { case 'innerzoom': lensdata.w = smallimagedata.w; lensdata.h = smallimagedata.h; break; default: lensdata.w = (settings.zoomWidth)/scale.x; lensdata.h = (settings.zoomHeight)/scale.y; break; } $( this.node ).css({ width: lensdata.w + 'px', height: lensdata.h + 'px', position: 'absolute', /*cursor: 'crosshair',*/ display: 'none', //border: '1px solid blue' borderWidth: 1+'px' }); a.append(this.node); } return this; }; Lens.prototype.activate = function() { //carico la lente this.loadlens(); switch(settings.zoomType) { case 'reverse': img.css({'opacity' : settings.imageOpacity}); (settings.alwaysOn) ? lens.center() : lens.setposition(null); //lens.center(); //bindo ad a il mousemove della lente a.bind( 'mousemove', function(e) { mousepos.x = e.pageX; mousepos.y = e.pageY; lens.setposition( e ); }); break; case 'innerzoom': // lens = new Lens(); // lens.activate(); $( this.node ).css({top : 0 ,left: 0}); if(settings.title) { ZoomTitleObj.loadtitle(); } largeimage.setcenter(); a.bind( 'mousemove', function(e) { mousepos.x = e.pageX; mousepos.y = e.pageY; largeimage.setinner( e ); /*if(settings.zoomType == 'innerzoom' && running) { $(a).mousemove(function(){ if($('div.jqZoomPup').length <= 0) { lens = new Lens(); lens.activate(); } }); }*/ /*if($('div.jqZoomPup').length <= 0) { lens = new Lens(); lens.activate(); }*/ }); break; default: /*$(document).mousemove(function(e){ if(isMouseDown && dragstatus != false){ lens.setposition( e ); } }); lens.center() dragstatus = 'on' $(document).mouseup(function(e){ if(isMouseDown && dragstatus != false){ isMouseDown = false; dragstatus = false; } }); $(this.node).mousedown(function(e){ $('div.jqZoomPup').css("cursor", "move"); $(this.node).css("position", "absolute"); // set z-index $(this.node).css("z-index", parseInt( new Date().getTime()/1000 )); if($.browser.safari) { $(a).css("cursor", "move"); } isMouseDown = true; dragstatus = 'on'; lens.setposition( e ); }); */ (settings.alwaysOn) ? lens.center() : lens.setposition(null); //bindo ad a il mousemove della lente $(a).bind( 'mousemove', function(e) { mousepos.x = e.pageX; mousepos.y = e.pageY; lens.setposition( e ); }); break; } return this; }; Lens.prototype.setposition = function( e) { if(e) { mousepos.x = e.pageX; mousepos.y = e.pageY; } if(firstime == 0) { var lensleft = (smallimagedata.w)/2 - (lensdata.w)/2 ; var lenstop = (smallimagedata.h)/2 - (lensdata.h)/2 ; //ADDED $('div.jqZoomPup').show() if(settings.lens) { this.node.style.visibility = 'visible'; } else { this.node.style.visibility = 'hidden'; $('div.jqZoomPup').hide(); } //ADDED firstime = 1; }else { var lensleft = mousepos.x - smallimagedata.pos.l - (lensdata.w)/2 ; var lenstop = mousepos.y - smallimagedata.pos.t -(lensdata.h)/2 ; } //a sinistra if(overleft()) { lensleft = 0 + bleft; }else //a destra if(overright()) { if($.browser.msie) { lensleft = smallimagedata.w - lensdata.w + bleft + 1 ; }else { lensleft = smallimagedata.w - lensdata.w + bleft - 1 ; } } //in alto if(overtop()) { lenstop = 0 + btop ; }else //sotto if(overbottom()) { if($.browser.msie) { lenstop = smallimagedata.h - lensdata.h + btop + 1 ; }else { lenstop = smallimagedata.h - lensdata.h - 1 + btop ; } } lensleft = parseInt(lensleft); lenstop = parseInt(lenstop); //setto lo zoom ed un eventuale immagine al centro $('div.jqZoomPup',a).css({top: lenstop,left: lensleft }); if(settings.zoomType == 'reverse') { $('div.jqZoomPup img',a).css({'position': 'absolute','top': -( lenstop - btop +1) ,'left': -(lensleft - bleft +1) }); } this.node.style.left = lensleft + 'px'; this.node.style.top = lenstop + 'px'; //setto l'immagine grande largeimage.setposition(); function overleft() { return mousepos.x - (lensdata.w +2*1)/2 - bleft < smallimagedata.pos.l; } function overright() { return mousepos.x + (lensdata.w + 2* 1)/2 > smallimagedata.pos.r + bleft ; } function overtop() { return mousepos.y - (lensdata.h + 2* 1)/2 - btop < smallimagedata.pos.t; } function overbottom() { return mousepos.y + (lensdata.h + 2* 1)/2 > smallimagedata.pos.b + btop; } return this; }; //mostra la lente al centro dell'immagine Lens.prototype.center = function() { $('div.jqZoomPup',a).css('display','none'); var lensleft = (smallimagedata.w)/2 - (lensdata.w)/2 ; var lenstop = (smallimagedata.h)/2 - (lensdata.h)/2; this.node.style.left = lensleft + 'px'; this.node.style.top = lenstop + 'px'; $('div.jqZoomPup',a).css({top: lenstop,left: lensleft }); if(settings.zoomType == 'reverse') { /*if($.browser.safari){ alert('safari'); alert(2*bleft); $('div.jqZoomPup img',a).css({'position': 'absolute','top': -( lenstop - btop +1) ,'left': -(lensleft - 2*bleft) }); }else {*/ $('div.jqZoomPup img',a).css({'position': 'absolute','top': -(lenstop - btop + 1) ,'left': -( lensleft - bleft +1) }); //} } largeimage.setposition(); if($.browser.msie) { $('div.jqZoomPup',a).show(); }else { setTimeout(function(){$('div.jqZoomPup').fadeIn('fast');},10); } }; //ritorna l'offset Lens.prototype.getoffset = function() { var o = {}; o.left = parseInt(this.node.style.left) ; o.top = parseInt(this.node.style.top) ; return o; }; //rimuove la lente Lens.prototype.remove = function() { if(settings.zoomType == 'innerzoom') { $('div.jqZoomPup',a).fadeOut('fast',function(){/*$('div.jqZoomPup img').remove();*/$(this).remove();}); }else { //$('div.jqZoomPup img').remove(); $('div.jqZoomPup',a).remove(); } }; Lens.prototype.findborder = function() { var bordertop = ''; bordertop = $('div.jqZoomPup').css('borderTop'); //alert(bordertop); lensbtop = ''; var borderleft = ''; borderleft = $('div.jqZoomPup').css('borderLeft'); lensbleft = ''; if($.browser.msie) { var temp = bordertop.split(' '); bordertop = temp[1]; var temp = borderleft.split(' '); borderleft = temp[1]; } if(bordertop) { for(i=0;i<3;i++) { var x = []; x = bordertop.substr(i,1); if(isNaN(x) == false) { lensbtop = lensbtop +''+ bordertop.substr(i,1); }else { break; } } } if(borderleft) { for(i=0;i<3;i++) { if(!isNaN(borderleft.substr(i,1))) { lensbleft = lensbleft + borderleft.substr(i,1) }else { break; } } } lensbtop = (lensbtop.length > 0) ? eval(lensbtop) : 0; lensbleft = (lensbleft.length > 0) ? eval(lensbleft) : 0; } //LARGEIMAGE function Largeimage( url ) { this.url = url; this.node = new Image(); /*if(settings.preloadImages) { preload.push(new Image()); preload.slice(-1).src = url ; }*/ this.loadimage = function() { if(!this.node) this.node = new Image(); this.node.style.position = 'absolute'; this.node.style.display = 'none'; this.node.style.left = '-5000px'; this.node.style.top = '10px'; loader = new Loader(); if(settings.showPreload && !preloadshow) { loader.show(); preloadshow = true; } document.body.appendChild( this.node ); this.node.src = this.url; // fires off async } this.node.onload = function() { this.style.display = 'block'; var w = Math.round($(this).width()); var h = Math.round($(this).height()); this.style.display = 'none'; //setting scale scale.x = (w / smallimagedata.w); scale.y = (h / smallimagedata.h); if($('div.preload').length > 0) { $('div.preload').remove(); } largeimageloaded = true; if(settings.zoomType != 'innerzoom' && running){ stage = new Stage(); stage.activate(); } if(running) { //alert('in'); lens = new Lens(); lens.activate() ; } //la attivo if($('div.preload').length > 0) { $('div.preload').remove(); } } return this; } Largeimage.prototype.setposition = function() { this.node.style.left = Math.ceil( - scale.x * parseInt(lens.getoffset().left) + bleft) + 'px'; this.node.style.top = Math.ceil( - scale.y * parseInt(lens.getoffset().top) +btop) + 'px'; }; //setto la posizione dell'immagine grande nel caso di innerzoom Largeimage.prototype.setinner = function(e) { this.node.style.left = Math.ceil( - scale.x * Math.abs(e.pageX - smallimagedata.pos.l)) + 'px'; this.node.style.top = Math.ceil( - scale.y * Math.abs(e.pageY - smallimagedata.pos.t)) + 'px'; $('div.jqZoomPup img',a).css({'position': 'absolute','top': this.node.style.top,'left': this.node.style.left }); }; Largeimage.prototype.setcenter = function() { this.node.style.left = Math.ceil(- scale.x * Math.abs((smallimagedata.w)/2)) + 'px'; this.node.style.top = Math.ceil( - scale.y * Math.abs((smallimagedata.h)/2)) + 'px'; $('div.jqZoomPup img',a).css({'position': 'absolute','top': this.node.style.top,'left': this.node.style.left }); }; //STAGE function Stage() { var leftpos = smallimagedata.pos.l; var toppos = smallimagedata.pos.t; //creating element and class this.node = document.createElement("div"); $(this.node).addClass('jqZoomWindow'); $( this.node ) .css({ position: 'absolute', width: Math.round(settings.zoomWidth) + 'px', height: Math.round(settings.zoomHeight) + 'px', display: 'none', zIndex: 10000, overflow: 'hidden' }); //fa il positionamento switch(settings.position) { case "right": leftpos = (smallimagedata.pos.r + Math.abs(settings.xOffset) + settings.zoomWidth < screen.width) ? (smallimagedata.pos.l + smallimagedata.w + Math.abs(settings.xOffset)) : (smallimagedata.pos.l - settings.zoomWidth - Math.abs(settings.xOffset)); topwindow = smallimagedata.pos.t + settings.yOffset + settings.zoomHeight; toppos = (topwindow < screen.height && topwindow > 0) ? smallimagedata.pos.t + settings.yOffset : smallimagedata.pos.t; break; case "left": leftpos = (smallimagedata.pos.l - Math.abs(settings.xOffset) - settings.zoomWidth > 0) ? (smallimagedata.pos.l - Math.abs(settings.xOffset) - settings.zoomWidth) : (smallimagedata.pos.l + smallimagedata.w + Math.abs(settings.xOffset)); topwindow = smallimagedata.pos.t + settings.yOffset + settings.zoomHeight; toppos = (topwindow < screen.height && topwindow > 0) ? smallimagedata.pos.t + settings.yOffset : smallimagedata.pos.t; break; case "top": toppos = (smallimagedata.pos.t - Math.abs(settings.yOffset) - settings.zoomHeight > 0) ? (smallimagedata.pos.t - Math.abs(settings.yOffset) - settings.zoomHeight) : (smallimagedata.pos.t + smallimagedata.h + Math.abs(settings.yOffset)); leftwindow = smallimagedata.pos.l + settings.xOffset + settings.zoomWidth; leftpos = (leftwindow < screen.width && leftwindow > 0) ? smallimagedata.pos.l + settings.xOffset : smallimagedata.pos.l; break; case "bottom": toppos = (smallimagedata.pos.b + Math.abs(settings.yOffset) + settings.zoomHeight < $('body').height()) ? (smallimagedata.pos.b + Math.abs(settings.yOffset)) : (smallimagedata.pos.t - settings.zoomHeight - Math.abs(settings.yOffset)); leftwindow = smallimagedata.pos.l + settings.xOffset + settings.zoomWidth; leftpos = (leftwindow < screen.width && leftwindow > 0) ? smallimagedata.pos.l + settings.xOffset : smallimagedata.pos.l; break; default: leftpos = (smallimagedata.pos.l + smallimagedata.w + settings.xOffset + settings.zoomWidth < screen.width) ? (smallimagedata.pos.l + smallimagedata.w + Math.abs(settings.xOffset)) : (smallimagedata.pos.l - settings.zoomWidth - Math.abs(settings.xOffset)); toppos = (smallimagedata.pos.b + Math.abs(settings.yOffset) + settings.zoomHeight < screen.height) ? (smallimagedata.pos.b + Math.abs(settings.yOffset)) : (smallimagedata.pos.t - settings.zoomHeight - Math.abs(settings.yOffset)); break; } this.node.style.left = leftpos + 'px'; this.node.style.top = toppos + 'px'; return this; } Stage.prototype.activate = function() { if ( !this.node.firstChild ) this.node.appendChild( largeimage.node ); if(settings.title) { ZoomTitleObj.loadtitle(); } document.body.appendChild( this.node ); switch(settings.showEffect) { case 'show': $(this.node).show(); break; case 'fadein': $(this.node).fadeIn(settings.fadeinSpeed); break; default: $(this.node).show(); break; } $(this.node).show(); if ($.browser.msie && $.browser.version < 7) { this.ieframe = $('<iframe class="zoom_ieframe" frameborder="0" src="#"></iframe>') .css({ position: "absolute", left:this.node.style.left,top:this.node.style.top,zIndex: 99,width:settings.zoomWidth,height:settings.zoomHeight }) .insertBefore(this.node); }; largeimage.node.style.display = 'block'; } Stage.prototype.remove = function() { switch(settings.hideEffect) { case 'hide': $('.jqZoomWindow').remove(); break; case 'fadeout': $('.jqZoomWindow').fadeOut(settings.fadeoutSpeed); break; default: $('.jqZoomWindow').remove(); break; } } function zoomTitle() { this.node = jQuery('<div />') .addClass('jqZoomTitle') .html('' + ZoomTitle +''); this.loadtitle = function() { if(settings.zoomType == 'innerzoom') { $(this.node) .css({position: 'absolute', top: smallimagedata.pos.b +3, left: (smallimagedata.pos.l+1), width:smallimagedata.w }) .appendTo('body'); }else { $(this.node).appendTo(stage.node); } }; } zoomTitle.prototype.remove = function() { $('.jqZoomTitle').remove(); } function Loader() { this.node = document.createElement("div"); $(this.node).addClass('preload'); $(this.node).html(settings.preloadText);//appendo il testo $(this.node ) .appendTo("body") .css('visibility','hidden'); this.show = function() { switch(settings.preloadPosition) { case 'center': loadertop = smallimagedata.pos.t + (smallimagedata.h - $(this.node ).height())/2; loaderleft = smallimagedata.pos.l + (smallimagedata.w - $(this.node ).width())/2; break; default: var loaderoffset = this.getoffset(); loadertop = !isNaN(loaderoffset.top) ? smallimagedata.pos.t + loaderoffset.top : smallimagedata.pos.t + 0; loaderleft = !isNaN(loaderoffset.left) ? smallimagedata.pos.l + loaderoffset.left : smallimagedata.pos.l + 0; break; } //setting position $(this.node).css({ top: loadertop , left: loaderleft , position: 'absolute', visibility:'visible' }); } return this; } Loader.prototype.getoffset = function() { var o = null; o = $('div.preload').offset(); return o; } }); } })(jQuery); function trim(stringa) { while (stringa.substring(0,1) == ' '){ stringa = stringa.substring(1, stringa.length); } while (stringa.substring(stringa.length-1, stringa.length) == ' '){ stringa = stringa.substring(0,stringa.length-1); } return stringa; }
插件描述:aos.js是一款效果超赞的页面滚动元素动画jQuery动画库插件。该动画库可以在页面滚动时提供28种不同的元素动画效果,以及多种easing效果。在页面往回滚动时,元素会恢复到原来的状态。 简要教程 aos.js是一款效果超赞的页面滚动元素动画jQuery动画库插件。该动画库可以在页面滚动时提供28种不同的元素动画效果,以及多种easing效果。在页面往回滚动时,元素会恢复到原来的状态。 安装 可以通过bower来安装aos动画库插件。 bower install aos --save 使用方法 在页面中引入aos.css文件,jquery和aos.js文件 <link rel="stylesheet" href="dist/aos.css" /> [removed][removed] [removed][removed] HTML结构 要使用aos动画库,你需要做的就是在需要动画的元素上添加aos属性,例如: aos脚本将会在页面滚动时,在该元素上触发相应的动画。 在元素上还可以添加以下一些属性: 属性 属性 属性 默认值 aos-offset 是立刻触发动画还是在指定时间之后触发动画 200 120 aos-duration 动画持续时间 600 400 aos-easing 动画的easing动画效果 ease-in-sine ease aos-delay 动画的延迟时间 300 0 aos-anchor 锚元素。使用它的偏移来取代实际元素的偏移来触发动画 #selector null aos-anchor-placement 锚位置,触发动画时元素位于屏幕的位置 top-center top-bottom aos-once 动画是否只会触发一次,或者每次上下滚动都会触发 true false 注意,aos-duration的动画持续时间的范围从50-3000毫秒,如果你想设置更大的值,可以在页面中添加下面的CSS代码: body[aos-duration='4000'] [aos], [aos][aos][aos-duration='4000']{ transition-duration: 4000ms; } 上面的代码将动画的持续时间修改为4000毫秒。 示例代码: 如果你担心HTML5校验的问题,可以为上面的属性添加data-前缀。 全局配置 如果你不想单独每个元素做一个动画配置,你可以通过init()方法来统一配置所有元素的动画效果。 AOS.init({ offset: 200, duration: 600, easing: 'ease-in-sine', delay: 100, }); 额外配置 AOS提供了2个额外的配置方法,这些方法只能够在初始化时使用。 配置 描述 示例值 默认值 disable AOS被禁用的条件 mobile false startEvent AOS被初始化的事件名称 exampleEvent DOMContentLoaded 禁用AOS: 如果你项在小屏幕设备中禁用AOS,可以: AOS.init({ disable: 'mobile' }); 你可以传入3种设备的类型:mobile、phone或tablet。 你也可以设置自己的禁用条件,例如在屏幕小于1024像素时禁用AOS: disable: window.innerWidth < 1024 或者传入一个函数,返回true或false。 disable: function () { var maxWidth = 1024; return window.innerWidth < maxWidth; } 开始动画的事件: 如果你不想滚动动画从页面加载(DOMContentLoaded)后就开始执行,可以使用startEvent来设置自己的事件,AOS会在document上监听这个事件: AOS.init({ startEvent: 'someCoolEvent' }); API AOS对象有2个可用的方法: init refresh AOS.refresh(); 上面的代码会重新计算元素的位置和偏移。 动画和锚位置 动画 淡入淡出动画: fade-up fade-down fade-left fade-right fade-up-right fade-up-left fade-down-right fade-down-left 翻转动画: flip-up flip-down flip-left flip-right 滑动动画: slide-up slide-down slide-left slide-right 缩放动画: zoom-in zoom-in-up zoom-in-down zoom-in-left zoom-in-right zoom-out zoom-out-up zoom-out-down zoom-out-left zoom-out-right 锚位置 top-bottom top-center top-top center-bottom center-center center-top bottom-bottom bottom-center bottom-top easing动画 你可以使用以下的一些easing动画效果: linear ease ease-in ease-out ease-in-out ease-in-back ease-out-back ease-in-out-back ease-in-sine ease-out-sine ease-in-out-sine ease-in-quad ease-out-quad ease-in-out-quad ease-in-cubic ease-out-cubic ease-in-out-cubic ease-in-quart ease-out-quart ease-in-out-quart

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值