简体   繁体   English

切换此元素而不是文本时,如何显示不同的图像

[英]How can I make different images display when this element is toggled, rather than text

I'm working on a project that already has most of the work completed. 我正在做一个已经完成大部分工作的项目。 I would just like to change this element to display images instead of the text "Pause Audio" and "Continue Audio". 我只想更改此元素以显示图像,而不是文本“暂停音频”和“继续音频”。

Thanks in advance. 提前致谢。

var player = new MediaElementPlayer('audio', {
    audioWidth: 0,
    features: [], 
    success: function (mediaElement, domObject) {}
});

var audioOn = true;
    var audioSrc = '';
    function playSoundClip(path)
    {
        player.pause();
        audioSrc = path;
        player.setSrc(audioSrc);        
        if (audioOn)
        {
            player.play();
        }
    }
    function audioToggle(toggleAnchor)
{
    if (audioOn)
    {
        player.pause();
        audioOn = false;
        $(toggleAnchor).html('**Continue Audio**');
    }
    else
    {
        audioOn = true;
        $(toggleAnchor).html('**Pause Audio'**);
        if (audioSrc.length > 0)
        {
            player.play();
        }
    }
}

只需将<img> html放入.html()函数中即可。

$(toggleAnchor).html('<img src="my/img/src.jpg">');

You should add the images into the HTML document first , so the user doesn't constantly request the same image from the host. 您应该添加图片到HTML文件首先 ,这样用户就不会不断地从主机请求相同的图像。 This helps reduce bandwidth usage, and also stops image flickering (when a new image is loaded). 这有助于减少带宽使用,还可以防止图像闪烁(加载新图像时)。 For example (contained in the element): 例如(包含在元素中):

<img src="img/blah" id="img1" style="display:none;">
<img src="img/blah" id="img2" style="display:inline;">

Then merely toggle their display attribute. 然后只需切换其显示属性。 This could also be done using Jquery's hide() and show() (if desired). 如果需要,也可以使用Jquery的hide()show()来完成。 Below is an example toggle function: 下面是一个示例切换功能:

function toggle(){
    if ($('img1').css('display') == 'none') {
        $('img1').css('display') = 'inline';
        $('img2').css('display') = 'none';
    }
    else {
        $('img1').css('display') = 'none';
        $('img2').css('display') = 'inline';
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在菜单元素上切换 class 时。 我怎样才能使 class 在以前切换的元素上被删除? - When toggling a class on a menu element. How can I make it so that class gets removed on previously toggled elements? 什么时候可以在react / react中使用reactDOM /如何使某些东西出现在屏幕上而不是在consoke中? - When can you use reactDOM in react/how can i make something appear on screen rather than in consoke? 如何使切换后的元素在开始时显示为块,然后在悬停时切换? - How can I make a toggled element appear block at start, then toggle on hover? 在单独的div标签中单击时,如何使每个标签显示不同的文本块? - How can I make each a tag display a different chunk of text when clicked in a separate div tag? p5.j​​s:当我的鼠标悬停在处理中的草图中不同的文本元素上时,如何使文本出现? - p5.js: How can I make text appear when my mouse hovers over a different text element in the sketch in processing? 如何创建一个使用4个图像来导航而不是文本的JQuery内容滑块? - How do I create a JQuery content slider that uses 4 images to navigate rather than text? p5.j​​s:当我的鼠标悬停在处理草图中的不同元素上时,如何使文本出现? - p5.js: How can I make text appear when my mouse hovers over a different element in the sketch in processing? CSS:我怎么能有一个“分散显示单词”而不是html默认显示上/下? - CSS: How can I have a “scatter display of words” rather than the html default display up/down? 如何使此滑块自动播放图像而不是单击 - how to make this slider autoplay the images rather than click 我如何制作未切换为默认切换的菜单 - How do i make a menu that's not toggled to be toggled by default
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM