[英]Change background color of a div temporarily on click and then set to a different color
Another noobie question. 另一个问题。 Trying to create a smartphone app using html, css, js and phonegap build. 尝试使用html,css,js和phonegap构建创建智能手机应用程序。 When the user taps a button or image I'd like to change the div background color from white to yellow, then play a short sound clip and then set the background color to say a pale yellow. 当用户点击按钮或图像时,我想将div背景颜色从白色更改为黄色,然后播放一个简短的声音片段,然后将背景颜色设置为浅黄色。
I will have dozens of these Divs and all have a class assigned. 我将有许多这样的Divs,并且都分配了一个班级。 Some will have a class .formal, others .informal and others .spanish. 有些将具有.formal类,另一些将具有.formal类,而另一些将具有.spanish类。 So far I can get it to play the sound only. 到目前为止,我只能让它播放声音。 I've tried adapting other solutions I've seen but the background color won't change. 我尝试调整其他见过的解决方案,但背景颜色不会改变。 I think I need to identify which instance of the class was clicked, then change only that bg color then play the sound and finally change the bg color to light yellow. 我想我需要确定单击了该类的哪个实例,然后仅更改该bg颜色,然后播放声音,最后将bg颜色更改为浅黄色。 I have removed some code for clarity below. 为了清楚起见,我删除了一些代码。
Thanks for any assistance you can provide me. 多谢您提供的协助。
Here's the html for a sample div 这是示例div的html
<div class="formal">
<a href="#" onclick="playAudio('/android_asset/www/test.mp3');">Play ay caramba</a>
</div>
And here's the "playAudio" js 这是“ playAudio” js
function playAudio(src) {
// Change bg color for the div to yellow here
if (my_media == null) {
// Create Media object from src
my_media = new Media(src, onSuccess, onError);
} // else play current audio
// Play audio
my_media.play();
// change background color to light yellow here
}
If can use jquery to do that 如果可以使用jQuery做到这一点
you will have something like that 你会有类似的东西
function playAudio(src) {
// Change bg color for the div to yellow here
$("formal").css('background-color','yellow');
if (my_media == null) {
// Create Media object from src
my_media = new Media(src, onSuccess, onError);
} // else play current audio
// Play audio
my_media.play();
// change background color to light yellow here
$("formal").css('background-color','blue');
}
you can put a hex color to get the color that you want 你可以放一个十六进制的颜色来得到你想要的颜色
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.