jquery - jquery代码中的背景位置

标签 jquery

在此代码中,添加背景位置来定位“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/

相关文章:

javascript - 如何计算两个DOM元素之间的关系? IE。他们有多密切相关)

jquery - 使用 addClass 向子子级添加类

javascript - 使用 JavaScript 或 jQuery 检测 CSS 变换 2D 是否可用

javascript - 仅当旁边有空格时,如何加宽 div?

javascript - 如何删除未选中的复选框上的文本框值?

jquery - 如何从ajax外部访问ajax变量

javascript - 如何访问功能键以将焦点添加到控件?

php - Jquery 获取数组所有元素

javascript - 如何使用 jQuery 在背景图像中分配 CSS 属性?

javascript - 创建一个简单的 JQuery 工具提示?