我左边有一个固定位置的手风琴菜单。当我单击子菜单项时,主页内容发生了变化,但jquery鼠标悬停功能不再起作用。
(参见菜单1 - >子菜单1 |子菜单2 |子菜单3) 。
这是页面内容加载器javascript函数:
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}
function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}
function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}
您可以查看mouse over/hover boxes here.
的示例这是我的菜单示例调用函数ajaxpage。
<li><a id='im1'><img src="img/vmenu-insert.jpg" id="1" align='left'>Menu 1</a>
<ul class='count'>
<li><a href="javascript:ajaxpage('boxes.php', 'boxes');">Sub-Menu 1</a></li>
<li><a href="javascript:ajaxpage('boxes2.php', 'boxes');">Sub-Menu 2</a></li>
<li><a href="javascript:ajaxpage('box.html', 'boxes');">Sub-Menu 3</a></li>
</ul>
</li>
如果有必要,这里是php代码示例,只需使用for循环加载多个框。
<?php
for ( $i = 0; $i<8; $i++ )
{
echo "<div class='vertscrollbox'>";
echo "<div class='slide imageslide'>";
echo "<div class='slidewrapper'>";
echo "<div class='image'> </div>";
echo "<h3>menu1 sub2</h3>";
echo "</div>";
echo "</div>";
echo "<div class='slide textslide'>";
echo "<div class='slidewrapper'>";
echo "<h3>menu1 sub2</h3>";
echo "<p>";
echo "LOREM IPSUM";
echo "</p>";
echo "</div>";
echo "</div>";
echo "</div>";
}
?>