嗨,我想做一個按鈕,首先翻轉圖片,然后在下一次點擊時,它將取消翻轉。 我嘗試了很多方法,但都沒有成功。
$('.button') 。 on("click", function (){
$('#image').css("transform","scaleX(-1)")。
})
uj5u.com熱心網友回復:
使用一個標志變數來保持變化的記錄。比如
。var flipFlag = 0 // initialy unfliped condition
$('.button').on("click", function (){
if(flipFlag == 0)
{
$('#image').css("transform","scaleX(-1)"); //翻轉表格
flipFlag=1; //1表示已翻轉。
}
else; //1 to say fliped }
{
$('#image').css("transform","scaleX(0)"); //原始形式
flipFlag=0; //0表示未被翻轉。
}
});
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
希望這能對你有所幫助,謝謝
uj5u.com熱心網友回復: 。document.getElementById('flipped')
.addEventListener('click', event => {
if(event.target.dataset.flipstate =='off') {
event.target.dataset.flipstate = 'on'/span>.
event.target.style.transform=("scaleX(-1)")。
} else {
event.target.dataset.flipstate = 'off'。
event.target.style.transform=("scaleX(1)")。
}
})
#flipped {
padding: 10px;
background: #BADA55;
}
<html>
<head>
<title>Example</title>
</head>
<body>
<img id="flipped"/span> src="https://www. fillmurray.com/g/200/300" alt="Bill Murray" data-flipstate="off">
</body>/span>
</html>/span>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/321019.html
標籤:
上一篇:領導為什么不聽我的匯報和授權方法
下一篇:如何每次都數到5而不是1
