jquery:关于$().css("left","&quo

1、css(“left”,””)

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

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



问题: $(“.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







jquery:关于$().css("left","&quo

相关文章:

你感兴趣的文章:

标签云: