2013-09-25 126 views

回答

2

這是非常簡單的。圖像右對齊,然後通過使用jQuery像低於25%降低它:

的jQuery:

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

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

+0

嗨,哈利,它滑到正確的罰款,但不是'收縮'(從左到右減少寬度從100%到0)。請看我的例子。謝謝 – IGIT

+0

@IGIT它從100%縮小爲0.除了與我相反的方向,與您的示例相同。 – Harry

+0

哈利,如果你看到我的例子,同時有兩個效果,而你的只有一個效果。 – IGIT

0

可能這有助於

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

你檢查demo

+0

嗨阿尼爾,這會將它全部滑向右側,但不會像我的示例那樣同時收縮它。謝謝 – IGIT

+0

我認爲它不會收縮 –

+0

Anil,在你的演示中,它向右滑動,這很好。但我也希望它在同一時間「縮小」(從左到右從100%減少到0)。請看我的例子。謝謝 – IGIT