简体   繁体   English

锚标签在触摸屏设备中无法正常工作

[英]Anchor tag is not working properly in touch screen devices

I've an anchor at the bottom of the page, which I am using to scroll to top of the page (to header). 我在页面底部有一个锚点 ,我用它来滚动到页面顶部(到标题)。

HTML: HTML:

<script type="text/javascript">Sys.Application.add_load(BindEventToScrolls);</script><%--Since I've achor tag within update panel, to rebind the jquery events after upade panel udates, I am using this line of code--%>
<a class="scrollToTopImg" href="#Header"></a>

CSS: CSS:

.scrollToTopImg
{
    background-repeat: no-repeat;
    background-position: right bottom;
    position: fixed;
    bottom: 34px;
    z-index: 999;
    right: 5px;
    color:#c1b38e;
    width:30px;
    height:30px;
    background-image: url('../Images/scrollToTop.png');
    background-size:100% 100%;
}

I am using following jquery to scroll smoothly 我正在使用以下jquery来顺利滚动

Jquery: jQuery的:

//BindEventToScrolls() is js function to rebind jquery events after update panel is updated
    function BindEventToScrolls() {
                $(document).ready(function () {
                    $('a').click(function () {
                        $('html, body').animate({
                            scrollTop: $($.attr(this, 'href')).offset().top
                        }, 2000);
                        return false;
                    });
                });
            }

Now in my touch device when I touch this anchor tag , the page scrolls to the top (to header) smoothly as exactly I wanted, but when I again try to wipe down to scroll page down , the page scrolls down but it again automatically scrolls smoothly towards top . 现在,当我触摸这个锚标签时,我的触摸设备 ,页面按照我想要的顺利滚动顶部 (到标题),但当我再次尝试向下擦动向下滚动页面时页面向下滚动但它再次自动滚动顺利地走向顶峰 I've to wipe down 3-4 times to finally scroll down and make page stay stable at that position . 我要擦拭3-4次 ,最后向下滚动 ,使页面在该位置保持稳定

The scrolling functionality is working exactly fine in desktop and non touch devices , but it is not at all working properly in touch devices . 滚动功能在桌面和非触摸设备中 工作得非常好 ,但在触摸设备中完全无法正常工作

I think the problem is with the jquery scroll which is not able to understand the touch events . 我认为问题在于jquery滚动无法理解触摸事件

Is there any way to solve this problem. 有没有办法解决这个问题。 Thanks in advance. 提前致谢。

function BindEventToScrolls() {
                $(document).ready(function () {
                    $('a').click(function () {
                        $('html, body').animate({
                            scrollTop: $($.attr(this, 'href')).offset().top
                        }, 2000);
                        event.preventDefault();
                    });
                });
            }

also try to add some values with offset it locate points for anchor element so add some value with this 还尝试添加一些带偏移的值,它为锚元素定位点,所以用这个添加一些值

var touchstart;
var touchend;
jQuery('.scrollableArea .expanded.dropdown').on('touchstart',function(e) {
    touchstart = e.originalEvent.touches[0].clientX;
//console.log(touchstart);
});
jQuery('.scrollableArea .expanded.dropdown').on('touchend', function(e) {
    touchend = e.originalEvent.changedTouches[0].clientX;
//console.log(touchend );
    if(touchend==touchstart) {
//console.log("Yesss"+jQuery(this).find('a').attr('href'));
     window.location = jQuery(this).find('a').attr('href');
    }
});

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

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