页面在模态弹出窗口中滚动到顶部

时间:2017-06-10 11:05:46

标签: javascript ajax twitter-bootstrap codeigniter bootstrap-modal

我正在使用bootstrap(前端)和codeigniter开发购物车。当添加到购物车项目时,模态弹出窗口显示添加项目的详细信息。但我的问题是页面滚动在模态弹出窗口中移动到顶部。

<a href="#" id="edit_product" data-id="<?php echo $lat['product_id'];?>" name="id" data-text="Add To Cart" class="my-cart-b item_add add_to_cart">Add To Cart</a>

的Ajax

$(".product_add").click(function(event) {

var currentId = globalId;


 $.ajax({
            type: 'POST',
            url: '<?php echo site_url("ajax_controller1/product_add/'+currentId+'")?>',
            data: { id:'1' }, 
            success:function(response){
              $("#cart_container1").html(response);
                $("#myModal3").modal('show');
     }
  });/* Aajx */



}); 

模态

<div class="modal fade" id="myModal3" tabindex="-1" role="dialog" style="overflow: visible;">
                <div class="modal-dialog" role="document" style="overflow: visible;">
                    <div class="modal-content modal-info" style="overflow: visible;">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>                        
                        </div>
                        <div class="modal-body" id="cart_container1">

                        </div>
                    </div>
                </div>
            </div>

我已经做了以下事情来克服这个问题

$('a.add_to_cart').click(function(e) {
    e.preventDefault();
});

body.modal-open {
    overflow: visible;
}

这是我的演示网站链接

  

http://cableandmedia.com/ayurstore/

1 个答案:

答案 0 :(得分:2)

我觉得罪魁祸首是href="#"

你可以做两件事,

  1. 只需删除href="#"
  2. 即可
  3. <a>更改为“

    <button type="button" id="edit_product" data-id="<?php echo $lat['product_id'];?>" name="id" data-text="Add To Cart" class="my-cart-b item_add add_to_cart">Add To Cart</button>

  4. 这应该对你有帮助。

    请注意,如果您遵循第二种方法,我已添加type="button"

相关问题