简体   繁体   English

jQuery,将div宽度从左向右缩小

[英]jQuery, shrink div width from left to right

As you can see there is a slide to the left and the with decreases from 100% to 0 at the same time. 如您所见,左侧有一张幻灯片,且同时从100%减少到0。

I want to get this same effect but from left to right. 我想获得相同的效果,但是从左到右。

I can't get it right! 我做错了!

jQuery('#target').animate({ width: '0', left: '-25%' }, 1500, 'swing');

Example Fiddle: http://jsfiddle.net/RsBNk/ 小提琴示例: http : //jsfiddle.net/RsBNk/

That is pretty simple. 那很简单。 Align the image to the right and then decrease it by 25% using jQuery like below: 将图像向右对齐,然后使用jQuery将其降低25%,如下所示:

jQuery: jQuery的:

jQuery('#target').animate({ width: '0', right: '-25%' }, 1500, 'swing');

CSS: CSS:

.box {
    width: 100%;
    position: absolute;
    top: 0;
    right: 0; /* Modified this line */
    height: 200px;
    background-image: url('http://images.icnetwork.co.uk/upl/uxbridgegazette/jul2012/0/4/marc-mccarroll-image-2-304314157.jpg');
    background-position: right; /* EDIT: This property needs to be set */
}

Updated Demo 更新的演示

May be this helps you 也许这可以帮助您

$('#target').animate({
    width : '0',
    marginLeft: parseInt($('#target').css('marginLeft'),10) == 0 ?
        $('#target').outerWidth() : 0
}, 1500, 'swing');

check demo 检查演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM