1
下面的函數需要一個options
參數和動畫元素,基於像素的特定amount
一個startValue
:是否有可能將元素恢復到之前的位置,而不將該位置作爲參數傳遞?
options: {
property: 'right',
startValue: '-250px',
amount: '250px'
},
function (options) {
const $el = $(this.el)
$el.click(() => {
const startValue = $el.parent().css(slide.property)
const calcValue = parseInt(startValue, 10) + parseInt(slide.amount, 10)
if (startValue === slide.startValue) {
$el.parent().animate({ [slide.property]: calcValue }, 200)
} else {
$el.parent().animate({ [slide.property]: slide.startValue }, 200)
}
})
}
但我不知道,是有可能實現相同的,而無需提供startValue
的功能? (例如如果right
初值爲0
然後將其還原到0
你第二次單擊該元素。)
恢復到以前的位置是什麼意思? – digglemister
@snookieordie我在問題中澄清了這一點。 – alexchenco