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

Yad*_*abu 3 javascript ajax codeigniter twitter-bootstrap bootstrap-modal

我正在使用引导程序(前端)和 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>
Run Code Online (Sandbox Code Playgroud)

阿贾克斯

$(".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 */



}); 
Run Code Online (Sandbox Code Playgroud)

模态

<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>
Run Code Online (Sandbox Code Playgroud)

我做了以下工作来克服这个问题

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

body.modal-open {
    overflow: visible;
}
Run Code Online (Sandbox Code Playgroud)

这是我的演示网站链接

http://cableandmedia.com/ayurstore/

Nir*_*aju 5

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

你可以做两件事,

  1. 只需删除 href="#"
  2. 更改<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>

这应该对你有帮助。

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