在此代码中,添加背景位置来定位“play.png”图像的正确方法是什么?
jQuery(document).ready(function($) {
var audioElement = document.createElement('audio');
$( ".audioplay img" ).click(function() {
audioElement.setAttribute('src', $(this).attr('data-href'));
if($(this).hasClass('playing')){
$(this).attr("src","/wp-content/player/play.png"); <<<<<< BACKGROUND POSITION
$('.audioplay img').removeClass("playing");
audioElement.pause();
}else{
$('.audioplay img').removeClass("playing");
$('.audioplay img').attr("src","/wp-content/player/play.png");
$(this).attr("src","/wp-content/player/stop.png");
$(this).addClass("playing");
audioElement.play();
}
});
});
最佳答案
尝试通过jquery添加css
$(this).css('background-position', '10px 10px');
如果您想删除背景位置
$(this).css('background-position', '');
关于jquery - jquery代码中的背景位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47108001/