Javascript 鼠标悬停效果不起作用
我这里有个奇怪的问题。我有一个隐藏的元素(display hidden),我想在鼠标移到另一个元素上时显示它。javscript似乎完成了这项工作,但当元素从display更改为hidden时,仍然没有发生任何事情;显示:块 这是我的html部分:Javascript 鼠标悬停效果不起作用,javascript,html,smarty,Javascript,Html,Smarty,我这里有个奇怪的问题。我有一个隐藏的元素(display hidden),我想在鼠标移到另一个元素上时显示它。javscript似乎完成了这项工作,但当元素从display更改为hidden时,仍然没有发生任何事情;显示:块 这是我的html部分: <div id="cart_block" class="block exclusive" style="display: none;"> a bunch more code in here, but I don't suppose
<div id="cart_block" class="block exclusive" style="display: none;">
a bunch more code in here, but I don't suppose I need to display that
</div>
这里还有很多代码,但我想我不需要显示它们
因为它位于smarty tpl文件中,所以我对javascript使用了literal。看起来是这样的:
<script type="text/javascript">
{literal}
document.getElementById('header_user').onmouseover=function(){
document.getElementById('cart_block').style.display='block';
};
document.getElementById('header_user').onmouseout=function(){
document.getElementById('cart_block').style.display='none';
};
{/literal}
{literal}
document.getElementById('header_user')。onmouseover=function(){
document.getElementById('cart_block').style.display='block';
};
document.getElementById('header_user')。onmouseout=function(){
document.getElementById('cart_block').style.display='none';
};
{/literal}
你可以在电视上看到它。如果您观察id为cart_block的元素,您应该会看到,当您将鼠标移到右上角的篮子上时,样式标记会发生变化,但它会保持隐藏状态。如果我从上面的html中删除style=“display:none”,它会显示我的元素,因此在我的脑海中应该可以使用。购物车块元素位于另一个设置了显示:none
的div中
以下块需要.top header.sf contenner从定义中删除,或者将cart_块元素移出此元素
.top-header #currencies_block_top, .top-header #header_links, .top-header #search_block_top, .top-header .sf-contener {
display: none;
}
使用document.ready
$(document).ready(function(){
document.getElementById('header_user').onmouseover=function(){
document.getElementById('cart_block').style.display='block';
};
document.getElementById('header_user').onmouseout=function(){
document.getElementById('cart_block').style.display='none';
};
});
这里还有很多代码,但我想我不需要显示它们
即使在上面设置了这些样式:
display:block;保证金:0;位置:绝对位置;浮动:左;顶部:0px;左:0px;宽度:100px;高度:100px代码>,我无法让它显示。不知道怎么回事,我只有这两个选择?问题是我对prestashop不是很在行-你提到的元素都是通过prestashop的hook_top调用调用的,så要将其移出,我想我必须添加一个新的hook并将cart_块连接到它。我不知道如何:(我还可以考虑做其他事情吗?我增加了可见性:隐藏;容器中的特定元素和删除显示:块;来自容器。这解决了问题。非常感谢!我不知道我必须考虑到这一点,所以谢谢:)这个函数被调用,所以我不认为使用docready是解决方案
<div id="header_user" style="width:100px; height:20px; border:1px solid black;"></div>
<div id="cart_block" class="block exclusive" style="display: none;">
a bunch more code in here, but I don't suppose I need to display that
</div>