将鼠标悬停在块元素上时HTML是否运行Javascript?
我目前正在努力使我的Tumblr页面尽可能的美观,并将其与其他页面区分开来。有一个带有菜单项的侧边栏,当用户将鼠标悬停在菜单项上时,这些菜单项会高亮显示并稍微向左移动。但是,我还希望在触发:hover时播放声音 这是侧边栏菜单代码将鼠标悬停在块元素上时HTML是否运行Javascript?,javascript,html,audio,triggers,hover,Javascript,Html,Audio,Triggers,Hover,我目前正在努力使我的Tumblr页面尽可能的美观,并将其与其他页面区分开来。有一个带有菜单项的侧边栏,当用户将鼠标悬停在菜单项上时,这些菜单项会高亮显示并稍微向左移动。但是,我还希望在触发:hover时播放声音 这是侧边栏菜单代码 #sidebar{ margin-left:85px; margin-top:50px; {block:IfNotStaticSidebar}position:absolute;{block:IfNotStaticSidebar} {block:IfStaticSid
#sidebar{
margin-left:85px;
margin-top:50px;
{block:IfNotStaticSidebar}position:absolute;{block:IfNotStaticSidebar}
{block:IfStaticSidebar}position:fixed;{/block:IfStaticSidebar}
background-color:{color:Sidebar};
width:200px;
padding:10px;
text-align:justify;
-moz-border-radius: 0px 50px 0px 0px;
-webkit-border-radius: 0px 50px 0px 0px;
-o-border-radius: 0px 50px 0px 0px;
border-radius: 0px 50px 0px 0px;
}
#description{
width:90%;
margin:10px;
}
a.block {
display:inline;
text-align: left;
font-size:10pt;
padding:3px;
margin:5px;
position:relative;
background-color:{color:color4};
display: inline-block;
font-family : arial;
color: {color:Menu Links Font};
font-weight: bold;
width: 100px;
transform: rotate(0deg);
-moz-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
}
a.block:hover {
color: {color:Menu Links Font Hover};
background-color:{color:color5};
padding-left:20px;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
text-shadow:0px 0px 5px {color:Shadow};
}
这是我正在尝试适应的声音代码
<script language="javascript" type="text/javascript">
function playSoun
d(soundfile) {
document.getElementById("dummy").innerHTML=
"<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
}
</script>
<span id="dummy"></span>
<p onmouseover="playSound('http://www.freesound.org/data/previews/141/141259_2555977-lq.mp3');"> Hover over this text </p>
函数playSoun
d(声音文件){
document.getElementById(“dummy”).innerHTML=
"";
}
将鼠标悬停在此文本上
我将非常感谢您的帮助 退房
它非常完美地解释了这一点!:)
下面是使用jQuery的一个技巧:
$("p").mouseenter(function(){
$("<audio></audio>").attr({
'src':'audio_src',
'volume':0.4,
'autoplay':'autoplay'
}).appendTo("body");
});
$(“p”).mouseenter(函数(){
$(“使用jquery
可以执行以下操作
<p id='psound'> </p>
鼠标入和鼠标出处理程序
<script type='text/javascript'>
$('#psound').hover(function (e) {
alert('on mouse over');
}, function (e) {
alert('on mouse out');
});
</script>