Jquery: Problem finding width
http://jsfiddle.net/KJGVE/
I am trying to make a slideshow/carousel, and as you can tell from the code, I am trying to make it on my own. Now when you click on the right arrow (forget left nav for now), the text block is supposed to scroll upwards(this works), and the image should slide out towards left. But for the image to slide out I need to get its width, or the width of the li
containing it, however I am getting width to be 9px
instead of 166
as I am supposed to. Any ideas?
PS: I know it is hard to understand in 开发者_高级运维there because there are no images, but if you can, please tell me if my way is correct or could I have shortened the code in any way.
as jchavannes said, $(this) refers to $(".cls_sshowbtn :next") to fix it, change the code as follows:
//Right Click
$(".cls_sshowbtn .next").click(function () {
$("#slideshow_horiz ul li:first").animate({
"margin-left": $("#slideshow_horiz ul li:first").width()
}, 1000, "easeInQuad", function () {
//$("#slideshow_horiz li:last").after($("#slideshow_horiz li:first"));
$("#slideshow_horiz li:last").css({
//"margin-left":"0"
});
});
});
精彩评论