开发者

how to set width of an element in jQuery

How do I set the width of the #book to width of #clickme a ? If I say $(this).width() in the callback function it gives me the width of #book.There are more than one anchor tags in #clickme.I need to increase the width at the end of the animation,please have a look at let me know

$('#clickme a').click(function() {
  $('#book').a开发者_StackOverflow中文版nimate({
    opacity: 0.25,
    left: '+=50',
    height: 'toggle'
  }, 5000, function() {
    //set width of #book to width of #clickme a item
  });
});

Thank You


Updated based on OP comment:

$("#clickme a").click(function() {
    var clicked = $(this);
    $("#book").animate({
        opacity: 0.25,
        left: "+=50",
        height: "toggle"
    }, 5000, function() {
        $(this).css("width", clicked.width())
    });
});


$('#clickme a').click(function() { 
    var aWidth = $(this).css("width");//alert(aWidth);
    $('#book').animate({
        opacity: 0.25,     left: '+=50',     height: 'toggle'   }, 500, 
        function() {   
            //set width of #book to width of #clickme a item   
            //alert($(this).css("width"));
            $(this).css("width",aWidth);
        });
}); 


$('#clickme a').click(function() {
  var _w = $(this).width();
  $('#book').animate({
    opacity: 0.25,
    left: '+=50',
    height: 'toggle'

  }, 5000, function() {
     $(this).width(_w);
  });
});


$('#book').width($("#clickme a").width())


You can try like this...

$('#clickme a').click(function() {
  $('#book').animate({
    opacity: 0.25,
    left: '+=50',
    height: 'toggle'
  }, 5000, function() {
     $(this).css('width','500');
  });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜