简体   繁体   English

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

[英]page scrolls to top on modal popup

I am developing a shopping cart using bootstrap(front end) and codeigniter. 我正在使用bootstrap(front end)和codeigniter开发购物车。 when add to cart item modal popup shows the details of added item. 当添加到购物车项目时,模态弹出窗口显示添加项目的详细信息。 But my issue is page scrolls moves to top on modal popup. 但是我的问题是页面滚动在模式弹出窗口上移至顶部。

<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 */



}); 

Modal 语气

<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>

I have done the following to overcome this issue 我已经做了以下工作来克服这个问题

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

body.modal-open {
    overflow: visible;
}

This is my demo website link 这是我的演示网站链接

http://cableandmedia.com/ayurstore/ http://cableandmedia.com/ayurstore/

I feel the culprit is href="#" 我认为罪魁祸首是href="#"

What you can do 2 things, 你可以做两件事,

  1. Just remove href="#" 只需删除href="#"
  2. Change <a> to ` <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>

This should help you. 这应该对您有帮助。

Notice that i have added type="button" if you are following 2nd approach. 请注意,如果您采用第二种方法,则我添加了type="button"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM