我遇到了与此post相同的问题, 但解决方案对我不起作用。它只是一个chrome问题,因为它在其他浏览器中运行良好。
任何想法?
我的固定导航代码:
<nav id="stick_nav" class="hide">
<div id="stick_nav_inner_wrapper">
<ul id="menu">
<li id="no_style">
<a href="<?php echo site_url('home');?>">
<img id="stick_nav_logo" class="clickable" src="<?php echo site_url();?>images/logo.png" style="width:95px"/>
</a>
</li>
<li class="<?php echo $marker_home;?>">
<a href="<?php echo site_url('home');?>">
Home
</a>
</li>
<li class="<?php echo $marker_about;?>">
<a href="<?php echo site_url('home/about');?>">
About
</a>
</li>
<li class="<?php echo $marker_prod;?>">
<a href="<?php echo site_url('home/products');?>">
Products
</a>
</li>
<li class="<?php echo $marker_basket;?>">
<span style="position:relative" class="basket_count" onclick="location.href='basket'">
<?php if(isset($_SESSION['basket'])){
$count = 0;
foreach ($_SESSION['basket'] as $item){
$count+= $item['qty'];
}
echo $count;
}else{
echo 0;
};
?>
</span>
</li>
</ul>
固定导航JS:
$(document).ready(function() {
var aboveHeight = $('header').outerHeight();
$(window).scroll(function(){
if ($(window).scrollTop() > aboveHeight){
$('#main_nav').fadeOut();
$('#stick_nav').fadeIn();
} else {
$('#stick_nav').fadeOut();
$('#main_nav').fadeIn();
}
});
});
更新固定导航中的计数的脚本:
require_once '../inc_basket.php';
$id = FilterData($_POST['id']);
$menu= new Menu();
$menu->getMenuData($id);
if($menu->data != ""){
foreach($menu->data as $md){
$basket = new ShoppingBasket();
$basket->Add($md['id'], $md['name'],$md['cat'],$md['price'], $md['class'], $md['description'],1);
if($basket->Success() == true){
if(isset($_SESSION['basket'])){
$count = 0;
foreach ($_SESSION['basket'] as $item){
$count+= $item['qty'];
}
?>
<script>
var count ='<?php echo $count;?>';
$('.basket_count').html('');
$('.basket_count').html(count);
</script>
<?php
}
}
?>
非常感谢任何帮助。