當某些 css 添加到一個元素時,我想更改頁面上的某些內容。我試過這個:if ($('.my-slider').css('transform') == 'translate3d(0px, 0px, 0px)') {
console.log('Logged');
}這是證明這個內聯樣式確實在頁面上的圖片:Image with my page source生成此樣式的 jQuery 插件“垂直輪播”。該插件的代碼位于該代碼之上,這不是問題。想法是在每次樣式更改時更改一些內容(變換值正在更改),但由于某種原因,這里的控制臺中沒有記錄任何內容...有人可以幫助我嗎?
2 回答

梵蒂岡之花
TA貢獻1900條經驗 獲得超5個贊
我認為你應該使用indexof函數。
if ($('.my-slider').attr('style') && $('.my-slider').attr('style').indexOf('translate3d(0px, 0px, 0px)') >= 0) { console.log('Logged'); }

慕標5832272
TA貢獻1966條經驗 獲得超4個贊
在各位的幫助下,問題已經解決了!我將提供以下代碼的工作版本,以防其他人需要它:
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutationRecord) {
if ((target.style.transform) == 'translate3d(0px, 0px, 0px)') {
console.log('logged');
}
});
var target = document.querySelector('.my-slider');
observer.observe(target, { attributes : true, attributeFilter : ['style'] });
- 2 回答
- 0 關注
- 140 瀏覽
添加回答
舉報
0/150
提交
取消